实验三 循环结构程序设计
#include "stdafx.h"
#include "stdio.h"
int main(int argc, char* argv[])
{
int i,s;
i = 22;
s = 0;
while (i<=1002)
{
s = s+i;
i = i+20;
}
printf("s=%d\n",s);
return 0;
}
#include "stdafx.h"
#include "stdio.h"
int main(int argc, char* argv[])
{
int i=22;
int s=0;
do
{
s = s+i;
i = i+20;
}
while (i<=1002);
printf("s=%d\n",s);
return 0;
}
#include "stdafx.h"
#include "stdio.h"
int main(int argc, char* argv[])
{
int i;
int s=0;
for (i=22;i<=1002;i+=20)
s=s+i;
printf("s=%d\n",s);
return 0;
}
#include "stdafx.h"
#include "stdio.h"
int main(int argc, char* argv[])
{
int i,a,b,c,d;
d = 0;
for(i=100;i<1000;i++)
{
a=i/100;
b=i%100/10;
c=i%100%10;
if(a*a*a+b*b*b+c*c*c==i)
{
printf("%d\n",i);
d++;
}
}
printf("水仙花数有%d个\n",d);
return 0;
}
#include "stdafx.h"
#include "stdio.h"
int main(int argc, char* argv[])
{
int a,b,c,d,e;
e=0;
for (a=1;a<6;a++)
{
for(b=1;b<6;b++)
{
for(c=1;c<6;c++)
{
if (a!=b&&a!=c&&b!=c)
{
d=a+10*b+c*100;
printf("%d ",d);
e++;
}
}
}
}
printf("共有%d个数\n",e);
return 0;
}