实验三

1.for循环

2.while循环

3.do while循环

2水仙花数

#include "stdafx.h" #include <stdio.h>

int main(){

 int a,b,c,d,e;

 int s=0

;  for(a=100;a<1000;a=a+1)

{   b=a/100;

  c=(a/10)%10;  

 d=a%10;  

 e=b*b*b+c*c*c+d*d*d;

  if(e==a){

  s++;   printf("水仙花数为%d\n",a);  

 }

 }

 printf("水仙花数的个数为%d\n",s);

 return 0;

}

3.0

#include "stdafx.h" #include <stdio.h>

int main()

{

 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&&b!=c&&a!=c)

{      d=a*100+b*10+c;   

   printf("三位数为%d\n",d);  

     e++;  

   }

   }

  }

 }

 printf("三位数有%d位\n",e);  

  return 0;

}

原文地址:https://www.cnblogs.com/P201821430026/p/10838647.html