#include <stdio.h> #include <stdlib.h> int main() { int number, max, min, n; n=1; printf("输入第%d个数: ", n); scanf("%d", &number); max = number; min = number; while(n<5) { n++; printf("输入第%d个数: ", n); scanf("%d", &number); if(number>max) max = number; else if(number<min) min = number; } printf("最大数为: %d\n", max); printf("最小数为: %d\n", min); system("pause"); return 0;
#include<stdio.h> #include<math.h> int main() { int k,i,m,n; n=0; for(k=101;k<=200;k++) { m=sqrt(k); for(i=2;i<=m;i++) if(k%i==0)break; if(i>m&&k>1) { printf("%d ",k); n=n+1; if(n%5==0) printf("\n"); } } printf("\n100~200之间有%d个素数",n); return 0; }
#include<stdio.h> int main() { long n; int j,k,z; printf("Enter a number :"); scanf("%ld",&n); printf("new number is:"); while (n>=10) { k=n; z=1; while(k!=0) { k=k/10; z=z*10; } z=z/10; j=n/z; if(j%2!=0) { printf("%d",j); } n=n-z*j; } if(n%2!=0) printf("%d",n); return 0;
}
#include<stdio.h> int main() { double s,n,a; int x,y; printf("Enter n and a:\n"); scanf("%lf%lf",&n,&a); x=1; y=a; do { s=s+x/a; a=a*10+y; x++; }while(x<=n); printf("s=%lf",s); return 0; }
总结:循环语句的嵌套不熟练。
原文:https://www.cnblogs.com/gu20010124/p/11902021.html