1.
(1)for循环
#include <stdio.h>
int main()
{
int n;
long int s;
s=0;
for(n=22;n<=1002;n=n+20)
s=s+n;
printf("总和=%d
",s);
return 0;
}
(2)while循环
#include <stdio.h>
int main()
{
int n;
long int s;
s=0;
n=22;
while(n<=1002)
{
s=s+n;
n=n+20;
}
printf("总和=%d
",s);
return 0;
}
(3)do-while 循环
#include <stdio.h>
int main()
{
int n;
long int s;
s=0;
n=22;
do
{
s=s+n;
n=n+20;
}
while(n<=1002);
printf("总和=%d
",s);
return 0;
}
2.
#include <stdio.h>
int main()
{ int a,b,c,n,num;
num=0;
for(n=100;n<1000;n++)
{ a=n/100;
b=(n-a*100)/10;
c=n%10;
if(n==a*a*a+b*b*b+c*c*c)
{
num++;
printf("%d ",n);
}
}
printf("水仙花的个数有%d个 ",num); return 0; }
3
#include "stdafx.h"
#include <stdio.h>
int main()
{
int a,b,c,t;
printf("符合要求的数字有%d个,分别是
",5*4*3);
for(t=0,a=1;a<=5;a++)//百位数有5种选择
for(b=1;b<=5;b++)
if(a!=b)
for(c=1;c<=5;c++)
if(c!=a && c!=b)
printf("%d
",a*100+b*10+c);
if(t%10)
printf("共有%d个
",t);
return 0;
}