RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
c语言水仙花数的函数,c语言用函数求水仙花数

c语言求水仙花数!!!!

你在定义变量的时候多定义一个整型变量

创新互联提供高防物理服务器租用、云服务器、香港服务器、服务器托管机柜

count用来计数;count初值设为0

if(a*a*a+b*b*b+c*c*c==i)

printf("%d\t",i);

在if里再加一条语句,count=count+1;即

if(a*a*a+b*b*b+c*c*c==i)

{

printf("%d\t",i);

count=count+1}

printf("水仙花的个数为:%d",count);

就可以了

C程序水仙花数用函数写

你需要对返回的数加一个判断,你的函数中,如果相等你有返回值,如果不相等你没有返回值,但是你的主函数中还是对这个没有返回的值进行了输出

#include stdio.h

int main()

{

int f(int m);

int n;

printf ("result is: ");

for (n = 100; n  1000; n++)

{

if (f(n)0)/////////////////////////

  printf ("%d ", f(n) );

}

printf ("\n");

return 0;

}

int f(int m)

{

int a,b,c;

a=m/100;

b=(m-a*100)/10;

c=m%10;

if(m==a*a*a+b*b*b+c*c*c)

return (m);

else return -1;////////////////////////

}

c语言调用函数求水仙花数

int li(int n)

{ return n*n*n;

}

int shuixian(int n)

{

int b,s,g;

b=n/100;

s=n/10%10;

g=n%10;

if((li(b)+li(s)+li(g))==n)

return 1;

return 0;

}

int main()

{

int i;

scanf("%d",i);

if(shuixian(i))

printf("%d\n",i);

return 0;

}

c语言求水仙花数

C语言输出水仙花数的具体分析和实现流程如下:

1、水仙花数的含义

“水仙花数”是一个三位数其各位数字的立方和等于该数本身。例如:3^3 + 7^3+ 0^3 = 370

2、算法分析

把给出的某个三位数的个位、十位、百位分别拆分,并求其立方和(设为sum),若sum与给出的三位数相等, 则为“水仙花数”。

3、算法设计

“水仙花数”是一个三位数,可以确定该数的取值范围是 100〜999。对应的循环条件如下:

for (n=10; n1000; n++) {}

将n整除以100,得出n在百位上的数字h。

将(n-i*100)整除以10, 得出n在十位上的数字t。

将n对10取余,得出n在个位上的数字a。

求得h,t,a 三个数字的立方和是否与n相等,如果相等则证明该数为水仙花数。

4、代码实现

#include stdio.h

int main() {

int h, t, a, n;

printf("result is:");

for ( n=100; n1000; n++ )  { /*整数的取值范围*/

h = n / 100;

t = (n-h*100) / 10;

a = n % 10;

if (n == h*h*h + t*t*t + a*a*a)  /*各位上的立方和是否与原数n相等*/

printf("%d  ", n);}

printf("\n");

return 0;}

扩展资料:

常见水仙花数

水仙花数又称阿姆斯特朗数。

1、三位的水仙花数共有4个:153,370,371,407;

2、四位的四叶玫瑰数共有3个:1634,8208,9474;

3、五位的五角星数共有3个:54748,92727,93084;

4、六位的六合数只有1个:548834;

5、七位的北斗七星数共有4个:1741725,4210818,9800817,9926315;

6、八位的八仙数共有3个:24678050,24678051,88593477

参考资料来源:百度百科-水仙花数


文章名称:c语言水仙花数的函数,c语言用函数求水仙花数
网页链接:http://sczitong.cn/article/hegssi.html