为什么不是scanf 的返回值declared with attribute 就是printf 就是if
水仙花数是指一个N位正整数(N≥3),它的每个位上的数字的N次幂之和等于它本身。例如:153=1
本题要求编写程序,计算所有N位水仙花数。
输入格式:
输入在一行中给出一个正整数N(3≤N≤7)。
输出格式:
按递增顺序输出所有N位水仙花数,每个数字占一行。
输入样例:
3
输出样例:
153
370
371
407
#include<stdio.h>
int main()
{
int n,a,x,b,i,e,S=0,c;
printf("please input a suitable integer:");
scanf("%d",&n);
switch(n){
case 3:a=100,b=999;break;
case 4:a=1000,b=9999;break;
case 5:a=10000,b=99999;break;
case 6:a=100000,b=999999;break;
case 7:a=1000000,b=9999999;break;
default:printf("error\n");break;
}
for(x=a;x<=b;x++)
{
for(i=1;i<n;i++)
{ e=x/10%10;
S=S+eee;
}
c=x%10;
S=S+ccc;
if (S==x)
printf("%d\n",x);
}
return 0;
}
pta说的编译错误:a.c: In function ‘main’:
a.c:23:10: error: stray ‘\357’ in program
if (S==x)
^
a.c:23:11: error: stray ‘\274’ in program
if (S==x)
^
a.c:23:12: error: stray ‘\210’ in program
if (S==x)
^
a.c:23:13: error: expected ‘(’ before ‘S’
if (S==x)
^
a.c:23:13: warning: statement with no effect [-Wunused-value]
a.c:23:7: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
if (S==x)
^~
a.c:23:17: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the ‘if’
if (S==x)
^
a.c:23:17: error: expected statement before ‘)’ token
a.c:6:5: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);