#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(max==min) { n++; printf("输入第%d个数: ", n); scanf("%d", &number); if(max<=number) max = number; else if(min>=number) min = number; } printf("最大数为: %d\n", max); printf("最小数为: %d\n", min); system("pause"); return 0; }
#include<stdio.h> #include<math.h> int main(){ int a,b=0,c; for(a=101;a<=200;a++){ for(c=2;c<=sqrt(a);c++){ if(a%c==0) break; } if(c>sqrt(a)){ printf("%4d",a); b++; if(b%5==0) printf("\n"); } } printf("101~200之间共有%d个素数\n",b); return 0; }
#include<stdio.h> int main(){ long s; printf("Enter a number:"); int a,b=0,c=1; scanf("%ld",&s); while(s>0){ a=s%10; s=s/10; if(a%2!=0){ b=b+a*c; c=c*10; } else b=b+0; } printf("A new number :%d",b); return 0; }
#include <stdio.h> int main(){ int n,i; float a,m,s,b; m=0;s=0; printf("Enter n and a:\n",n,a); scanf("%d%f",&n,&a); for(i=1;i<=n;i++){ m=a+m*10; b=1/m; s=s+b; } printf("%f\n",s); return 0; }
对于数据类型的定义不清晰,在写程序时容易弄错,导致运行结果奇怪。