C语言,编程题,谢谢大佬!

2024-12-01 03:11:44
推荐回答(3个)
回答1:

#include

int main()

{ int m,n,i,t,i1,k=0;

scanf("%d%d",&m,&n);

for(i=m; i<=n; i++)

{ t=0;

for(i1=i; i1; i1/=10)

t+=i1%10;

if(t==5)

{ printf("%d ",i);

k++;

}

}

printf("\ncount = %d\n",k);

return 0;

}

回答2:

#include
int main()
{
int M;
int N;
int i;
int count = 0;
//printf("input the M:");
scanf("%d %d",&M,&N);
//printf("input the N:");
//scanf("%d",&N);
for(i = M;i<=N;i++)
{
if(is_five(i)==1)
{
count++;
printf("%d ",i);
}
}
putchar('\n');
printf("count=%d\n",count);

}
//编写一个判断一个数各位之和是否为5
int is_five(int num)
{
int s = 0;
int temp = num;
while(temp)
{
s += temp%10;
temp = temp/10;
}
if(s==5)
{
return 1;
}
else
{
return 0;
}
}

回答3:

#include int main(int argc, char *argv[]){ int i = 0; int a[10] = {0}; int pass_cnt = 0; for (i = 0; i 10; i++) { printf("请输入第%d位学生的考试结果:\n", i+1); scanf("%d", &a[i]); if (1 == a[i]) { pass_cnt++; } else if (2 != a[i]) { printf("错误的输入\n"); i--; } } if (pass_cnt >= 10) { printf("Too easy\n"); } return 0;}