实验三 循环结构程序设计
作者:互联网
#include"stdio.h" int main(){ int a,i; for(a = 22,i = 0;a <= 1002;a = a+20){ i = i+a; } printf("%d\n",i); return 0; }
#include"stdio.h" int main(){ int a,i; a = 22; i = 0; while(a<=1002){ i = a+i; a = a+20; } printf("%d\n",i); return 0; }
#include"stdio.h" int main(){ int a,i; a = 22; i = 0; do{ i = a+i; a = a + 20; }while(a<=1002); printf("%d\n",i); return 0; }
二、水仙花数
#include"stdio.h" int main(){ int a,b,c; int shuzi,jishu; for(shuzi = 100,jishu = 0;shuzi<=999;shuzi++){ c = shuzi%10; a = (shuzi - (shuzi%100))/100; b = ((shuzi%100)-c)/10; if(a*a*a+b*b*b+c*c*c == shuzi){ printf("%d是水仙花数\n",shuzi); jishu++; }} printf("一共有%d个水仙花数",jishu); return 0;
三、数字组合
#include"stdio.h" int main(){ int i,j,k,n; n = 0; for(i = 1;i<=5;i++){ for(j = 1;j<=5;j++){ for(k = 1;k<=5;k++){ if(i!=j&&j!=k&&i!=k){ printf("%d%d%d ",i,j,k); n++; if(n%5==0){ printf("\n"); } } } } } printf("一共有%d种组合\n",n); return 0; }
标签:include,22,int,stdio,shuzi,循环,实验,程序设计,main 来源: https://www.cnblogs.com/p201821440032/p/10750446.html