慕仔0927226
2017-07-30 15:53
#include <stdio.h>
int main()
{
//定义三位数num,个位数sd,十位数td,百位数hd
int num, sd, td, hd;
//循环所有三位数
for( ? ; ? ; ? )
{
//获取三位数字num百位上的数字
hd = ? ;
//获取三位数字num十位上的数字
td = ? ;
//获取三位数字num个位上的数字
sd = ? ;
//水仙花数的条件是什么?
if( ?? )
{
printf("水仙花数字:%d\n", num);
}
}
return 0;
刚才错了
#include <stdio.h>
int main()
{
//定义三位数num,个位数sd,十位数td,百位数hd
int num, sd, td, hd;
//循环所有三位数
for( num = 100 ; num < 1000 ; num++ )
{
//获取三位数字num百位上的数字
hd = num / 100 ;
//获取三位数字num十位上的数字
td = (num % 100) / 10 ;
//获取三位数字num个位上的数字
sd = num % 10 ;
//水仙花数的条件是什么?
if( num == hd*hd*hd + td*td*td +sd*sd*sd )
{
printf("水仙花数字:%d\n", num);
}
}
return 0;
}
#include <stdio.h>
int main()
{
//定义三位数num,个位数sd,十位数td,百位数hd
int num, sd, td, hd;
//循环所有三位数
for( num = 100 ; num < 1000 ; num ++ )
{
//获取三位数字num百位上的数字
hd = num / 100 ;
//获取三位数字num十位上的数字
td = (num % 100) / 10 ;
//获取三位数字num个位上的数字
sd = num / 10 ;
//水仙花数的条件是什么?
if( num = hd*hd*hd + td*td*td +sd*sd*sd )
{
printf("水仙花数字:%d\n", num);
}
}
return 0;
}
C语言入门
926353 学习 · 20799 问题
相似问题