实验2
1 #include<stdio.h> 2 #include<math.h> 3 #include<time.h> 4 #define N 5 5 #define N1 397 6 #define N2 476 7 #define N3 21 8 int main() 9 { 10 int cnt ; 11 int random_major,random_no; 12 srand(time(NULL)); 13 cnt = 0; 14 while (cnt<N) 15 {random_major =rand ()%2; 16 if (random_major) 17 {random_no=rand()%(N2-N1+1)+N1; 18 printf("20248329%04d\n",random_no); 19 } 20 else {random_no=rand()%N3+1; 21 printf("20248325%04d\n",random_no); 22 } 23 cnt++;} 24 return 0;
问题1,抽取计算机11到12班任意学号
问题2,抽取奇安信班任意学号
问题3,在计算机班中抽取4个任意学号
2
1 #include <stdio.h> 2 #include <math.h> 3 int main() { 4 double a, b, c; 5 double delta, p1, p2; 6 while (scanf("%lf%lf%lf", &a, &b, &c) != EOF) { 7 if (a == 0) { 8 printf("a = 0, invalid input\n"); 9 continue; 10 } 11 delta = b * b - 4 * a * c; 12 p1 = -b / 2 / a; 13 p2 = sqrt(fabs(delta)) / 2 / a; 14 if (delta == 0) 15 printf("x1 = x2 = %.2g\n", p1); 16 else if (delta > 0) 17 printf("x1 = %.2g, x2 = %.2g\n", p1 + p2, p1 - p2); 18 else { 19 printf("x1 = %.2g + %.2gi, ", p1, p2); 20 printf("x2 = %.2g - %.2gi\n", p1, p2); 21 } 22 } 23 return 0; 24 }
1 #include<stdio.h> 2 #include<stdio.h> 3 int main() 4 { 5 char ch; 6 while (scanf("%c", &ch) != EOF) 7 if (ch == 'y') 8 { 9 printf("wait a minute\n"); 10 getchar(); 11 } 12 else if (ch == 'g') 13 { 14 printf("go go go\n"); 15 getchar(); 16 } 17 else if (ch == 'r') 18 { 19 printf("stop!\n"); 20 getchar(); 21 } 22 else { 23 printf("something must be wrong\n"); getchar(); 24 } 25 return 0; 26 }
1 #include<stdio.h> 2 int main() 3 { 4 double a; 5 double b = 0; 6 double max = 0; 7 double min = 20000; 8 while (scanf("%lf", &a) != EOF) 9 { 10 if (a == -1) 11 break; 12 else if (a > max && a < min) 13 { 14 max = a; 15 min = a; 16 } 17 else if (a < min && a < max) 18 { 19 min = a; 20 } 21 else if (a > min && a > max) 22 { 23 max = a; 24 }b = a + b; 25 } 26 printf("今日累计消费:%.1f\n", b); 27 printf("今日最高消费:%.1f\n", max); 28 printf("今日最低消费:%.1f\n", min); 29 return 0; 30 }
1 #include<stdio.h> 2 int main() 3 { 4 int a, b, c; 5 while (scanf("%d%d%d", &a, &b, &c) != EOF) 6 if (a + b <= c || a + c <= b || b + c <= a) 7 { 8 printf("不能构成三角形\n"); 9 getchar(); 10 } 11 else if (a == b || b == c || c == a) 12 { 13 if (a == b&&b== c) 14 printf("构成等边三角形\n"); 15 else printf("构成等腰三角形\n"); 16 getchar(); 17 } 18 else if (a*a+b*b==c*c||a*a+c*c==b*b||b*b+c*c==a*a) 19 { 20 printf("构成直角三角形\n"); 21 getchar(); 22 } 23 else { 24 printf("构成普通三角形\n"); 25 getchar(); 26 }return 0; 27 }
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<time.h> 4 int main() 5 { 6 int luckyday, a, s; 7 s = 0; 8 srand(time(NULL)); 9 luckyday = rand() % 30 + 1; 10 printf("猜猜2024年11月哪一天是你的luckyday吧\n"); 11 while (s < 3) 12 { 13 scanf("%d", &a); 14 s++; 15 if (a == luckyday) 16 { 17 printf("哇,你猜对了\n"); 18 break; 19 } 20 else if (a < luckyday) 21 { 22 printf("猜早了,你的luckyday还没到呢\n"); 23 } 24 else printf("猜晚了,你的luckyday在前面呢\n"); 25 26 } 27 if (s == 3) 28 printf("次数用光了,偷偷告诉你,11月的luckyday是%d号\n",luckyday); 29 return 0; 30 }