27、写一个函数,判断某一个四位数是否玫瑰花数 用C语言写

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了27、写一个函数,判断某一个四位数是否玫瑰花数 用C语言写相关的知识,希望对你有一定的参考价值。

27、写一个函数,判断某一个四位数是不是玫瑰花数(所谓玫瑰花数即
该四位数各位数字的四次方和恰好等于该数本身,如:1634=14+64+34+44)
。在主函数中从键盘任意输入一个四位数,调用该函数,判断该数是否
为玫瑰花数,若是则输出“yes”,否则输出“no”。

参考技术A #include<stdio.h>
#include<math.h>
void main()

scanf("请输入任意一个千位数:%d",n);
int total=0;
int chushu=10000;
int x=n;
while(chushu!=1)

x=n%chushu;
total+=pow(x/(chushu/10),4);
chushu /= 10;

string result = total==n?"yes":"no";
printf(result);
本回答被提问者采纳
参考技术B #include<stdio.h>
void main()

char n[4];
int num=sum=0;
scanf("%s",n);
for(int i=0;i<4;i++)

a=n[i]-'0';
sum+=a*a*a*a;
num=num*10+a;

if(sum==num) printf("yes");
else printf("no");
参考技术C #include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()

int x,k,s,total=0;
scanf("%d",&x);
s=x;
while(x!=0)
k=x%10; x=x/10; total+=(int)pow((double)k,4.0);
if(total==s) printf("\nYes\n");
else printf("\nNo\n");
system("pause");

第一次用,我就写写

第一次用,我就写写第一次用,我就写写第一次用,我就写写第一次用,我就写写第一次用,我就写写第一次用,我就写写第一次用,我就写写第一次用,我就写写

本文出自 “12088313” 博客,请务必保留此出处http://12098313.blog.51cto.com/12088313/1890132

以上是关于27、写一个函数,判断某一个四位数是否玫瑰花数 用C语言写的主要内容,如果未能解决你的问题,请参考以下文章

用python定义一个函数判断三位数是否回文数?

POJ 3126 Prime PathBFS

三重循环实现四位的吸血鬼数

c语言中,如何输出所有的水仙花数

写一个函数,判断一个正整数是否是水仙花数(扩展n位的自幂数)

四叶玫瑰数