注意事项:
题目说的“数之间用两个空格分开”,其实是一个空格!!
一个数确定位数,然后根据位数,进行立方求和;遍历一遍就行。
最后的结果用数组存储,输出最后一位时不保留空格。
参考代码:
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
int main()
{
int a[100];
int length=0;
for(int i=2;i<1000;i++)
{
int count=0;
int j=i;
while(j)
{
count++;
j/=10;
}
if(count==2)
{
if(i==(pow(i/10,3)+pow(i-i/10*10,3)))
{
a[length]=i;
length++;
}
}
if(count==3)
{
if(i==(pow(i/100,3)+pow((i-i/100*100)/10,3)+pow(i%10,3)))
{
a[length]=i;
length++;
}
}
}
for(int i=0;i<length;i++)
{
if(i!=length-1)
printf("%d ",a[i]);
else
printf("%d",a[i]);
}
return 0;
}
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:600 |
【偶数求和】 (C语言代码)浏览:646 |
WU-图形输出 (C++代码)浏览:802 |
用筛法求之N内的素数。 (C语言代码)浏览:649 |
C语言程序设计教程(第三版)课后习题8.4 (C语言代码)浏览:609 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:543 |
出圈】指针malloc版浏览:355 |
简单的a+b (C语言代码)浏览:950 |
简单的a+b (C语言代码)浏览:630 |
简单的a+b (C语言代码)浏览:830 |