「NOIP」 聯賽模擬測試33
阿新 • • 發佈:2020-11-19
1 #include <math.h> 2 #include <stdio.h> 3 4 int main() 5 { 6 float a, b, c, x1, x2; 7 float delta, real, imag; 8 9 printf("Enter a, b, c: "); 10 11 while(scanf("%f%f%f", &a, &b, &c) != EOF) 12 { 13 if(a == 0) 14 { printf("not quadratic equation.\n\n"); } 15 else 16 { delta = b*b - 4*a*c; } 17 18 if(delta >= 0) 19 { 20 x1 = (-b + sqrt(delta)) / (2*a); 21 x2 = (-b - sqrt(delta)) / (2*a); 22 printf("x1 = %.2f, x2 = %.2f\n\n", x1, x2); 23 } 24 else 25 { 26 real = -b/(2*a); 27 imag = sqrt(-delta) / (2*a); 28 printf("x1 = %.2f + %.2fi, x2 = %.2f - %.2fi\n\n", real,imag,real,imag); 29 } 30 31 printf("Enter a, b, c: "); 32 } 33 34 return 0; 35 }
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <time.h> 4 #define N 5 5int main() { 6 int x, n; 7 8 srand(time(0)); // 以當前系統時間作為隨機種子 9 n = 0; 10 11 do { 12 n++; 13 x = rand()%10; // 生成一個0~9之間的隨機整數 14 printf("%3d", x); 15 }while(n<N); 16 17 printf("\n"); 18 19 return 0; 20 }
1 #include <stdio.h> 2 #include <math.h> 3 4 int main() 5 { 6 int n=100,a=0,m=2; 7 8 while(n<200) 9 { 10 while(m <=sqrt(n)) 11 { 12 if(n%m!=0) 13 {m+=1;} 14 else 15 {break;} 16 } 17 if(m>sqrt(n)) 18 { 19 printf("%d\n",n); 20 a+=1; 21 } 22 n+=1; 23 m=2; 24 } 25 printf("個數為%d",a); 26 27 return 0; 28 }
1 #include <stdio.h> 2 #include <math.h> 3 4 int main() 5 { 6 int a,b,c,sum=0,n=0; 7 8 while(scanf("%d",&a) != EOF) 9 { 10 11 while(a>0) 12 { 13 b=a%10; 14 a/=10; 15 if(b==1||b%2==1) 16 { 17 c=b*pow(10,n); 18 n+=1; 19 sum+=c; 20 } 21 } 22 printf("%d\n",sum); 23 printf("\n"); 24 sum=0; 25 n=0; 26 } 27 28 return 0; 29 }
1 #include <stdio.h> 2 #include <math.h> 3 4 int f(int); 5 int f(int k) 6 { 7 int m=k; 8 9 if (k > 1) 10 { 11 while (k > 1) 12 { 13 m = m* (k - 1); 14 k = k - 1; 15 } 16 } 17 else 18 m = 1; 19 20 21 return m; 22 } 23 24 25 int main() 26 { 27 int n,x; 28 double a = 1,sum=0; 29 30 while (scanf("%d", &n)!=EOF) 31 { 32 if (n < 1 || n>10) 33 { 34 printf("請輸入1到10間的數字"); 35 } 36 else 37 { 38 while (n > 0) 39 { 40 x = f(n); 41 sum += a / x * pow(-1, n - 1); 42 n = n - 1; 43 } 44 } 45 46 printf("%lf\n", sum); 47 printf("\n") ; 48 a = 1; 49 sum = 0; 50 } 51 52 53 return 0; 54 }
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 int main() 5 { 6 int a,b,k=1; 7 a=rand()%32; 8 9 while(k<4) 10 { 11 scanf("%d",&b); 12 k+=1; 13 14 if(b==a) 15 { 16 printf("猜對了\n"); 17 break; 18 } 19 else if(b<a) 20 {printf("猜小了\n");} 21 else 22 {printf("猜大了\n");} 23 } 24 25 if(k==4) 26 {printf("次數用完,答案為%d",a);} 27 else 28 {printf("猜對了,答案為%d",a);} 29 30 return 0; 31 }