c语言中什么是玫瑰花数

c语言中什么是玫瑰花数,第1张

# include <iostreamh>

# include <mathh>

# define SIZE 10

int main()

{

long i,j;

long a[SIZE];

long temp;

long count=0;

long sum=0;

cout<<"玫瑰花数:"<<endl;

for(i=(long)(pow(10,4-1));i<(long)pow(10,4);i++)

{

temp=i;

while(temp!=0)

{

a[count++]=temp%10;

temp/=10;

}

for(j=0;j<count;j++)

{

sum+=(long)(pow(a[j],4));

}

if(sum==i)

{

while(count>1)

{

cout<<a[--count]<<"^"<<4<<"+";

}

cout<<a[--count]<<"^"<<4<<"="<<sum<<endl;

}

sum=0;

count=0;

}

return 0;

}

可以了哈,试试嘛

#include <stdioh>

main()

{

// 从键盘上输入一个四位数,判断其是否为四叶玫瑰数

// (提示:四叶玫瑰数是指一个四位数,它的每个位上的数字的4次幂之和等于它本身)

int rose,one,two,three,four;

scanf("%d",&rose);//

four=rose/1000;

three=rose/100%10;

two=rose/10%10;

one=rose%10;

four=fourfourfourfour;

three=threethreethreethree;

two=twotwotwotwo;

one=oneoneoneone;

if((four+three+two+one)==rose)

printf("%d",rose);

}

这个是tc专有的

说明原始程序

是用tc编写 编译的

用vs 或者vc都无法运行

你如果要用这个程序 需要针对vc进行修改

或者改用TC20

代码文本:

#include "stdioh"

int main(int argc,char argv[]){

int n,t;

n=999;

while(++n<10000)

if(n==(t=n/1000)ttt+(t=n/100%10)ttt+(t=n/10%10)ttt+(t=n%10)ttt)

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

return 0;

}

欢迎分享,转载请注明来源:浪漫分享网

原文地址:https://hunlipic.com/langman/3265951.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-08-13
下一篇2023-08-13

发表评论

登录后才能评论

评论列表(0条)

    保存