| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 13292 人关注过本帖
标题:怎样求出所有水仙花数?
只看楼主 加入收藏
zhuxu0423
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:59
专家分:101
注 册:2010-4-12
收藏
得分:0 
#include<stdio.h>
void main()
{
int i,j,k,n;
printf("100~999之间的所有水仙花数 are:\n");
for(n=100;n<1000;n++)
{
i=n/100;
j=n/10-i*10;
k=n%10;
if(n==i*i*i+j*j*j+k*k*k)
printf("%d  ",n);
}
printf("\n");
}
2010-04-14 17:46
xx5242202628
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-12-4
收藏
得分:0 
回复3楼:我运行了楼中的程序出现以下结果:
--------------------Configuration: 1111 - Win32 Debug--------------------
Compiling...
1111.cpp
C:\Program Files\Visual C++\Bin\1111.cpp(6) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(6) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(7) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(7) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(8) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(8) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(8) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(8) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(9) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(9) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(9) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(9) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(10) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(10) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(10) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(10) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(11) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(11) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(11) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(11) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(12) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(12) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(12) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(12) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(12) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(12) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(13) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(13) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(13) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(13) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(13) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(13) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(14) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(14) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(14) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(14) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(14) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(14) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(15) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(15) : error C2018: unknown character '0xa1'
C:\Program Files\Visual C++\Bin\1111.cpp(17) : warning C4508: 'main' : function should return a value; 'void' return type assumed
Error executing cl.exe.

1111.exe - 40 error(s), 1 warning(s)

这是为什么呢,如何解决?
2010-12-04 09:20
hsfree
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2016-1-27
收藏
得分:0 
#include<stdio.h>
#include<math.h>

int main()
{
    int a = 3, b, c, d, e, f, g, h, l, m;//a是数 ,b是被判断位数的数, c是位数。

    for (; a <= 1000000000; a++)
    {
        b = a;
        c = 1;
        h = 0; //h一个循环里面都要清零
        while (b >= 10)
        {

            b /= 10;
            c++;
        }
        f = c;
        b = a;
        do
        {
            e = 1;
            d = 1;
            for (; d < f; d++)
            /*for (d = 1; d < f; d++) 如果再循环的话 d是等于1 还是是f-1*/
            {
                e = e * 10;
            }
            f -= 1;
            g = b / e;

            /*h += pow(int g,int c);*/ //这个怎么用
            l = 1;
            m = 1;
            for (; l <= c; l++)
            {
                m *= g;
            }
            h += m;
            b -= g * e;
        } while (f >= 0);
        if (h == a)
        {
            printf("%d\t", a);
        }
    }
    return 0;
}
2016-01-27 00:15
hsfree
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2016-1-27
收藏
得分:0 
回复 13楼 hsfree
自己写的 希望能帮到
2016-01-27 00:16
快速回复:怎样求出所有水仙花数?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.029174 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved