任务1
问题1:答:给 random_no 随机赋值为 398 — 476 中的一个值。
问题2:答:给 random_no 随机赋值为 3 — 21 中的一个值。
问题3:答:随机生成 202483290003 — 202483290021 或 202483290398 — 202483290476 范围中的5个学号
实验二
1 #include<stdio.h> 2 #include<math.h> 3 4 int main() 5 { 6 double a, b, c; 7 double delta, p1, p2; 8 9 while (scanf_s("%lf%lf%lf", &a, &b, &c) != EOF) 10 { 11 if (a == 0) { 12 printf("a = 0, invalid input\n"); 13 continue; 14 15 } 16 17 delta = b * b - 4 * a * c; 18 p1 = -b / 2 / a; 19 p2 = sqrt(fabs(delta)) / 2 / a; 20 21 if (delta == 0) 22 printf("x1 = x2 = %.2g\n", p1); 23 else if (delta < 0) 24 printf("x1 = %.2g, x2 = %.2g\n", p1 + 25 p2, p1 - p2); 26 else { 27 printf("x1 = %.2g + %.2gi, ", p1, p2); 28 printf("x2 = %.2g - %.2gi\n", p1, p2); 29 } 30 } 31 return 0; 32 }
实验三
1 #include<stdio.h> 2 int main () 3 { 4 5 char colour; 6 while (scanf("%c",&colour) != EOF){ 7 if (colour == 'r') 8 printf("stop!\n"); 9 else if(colour == 'y') 10 printf("wait a minute\n"); 11 else if(colour == 'g') 12 printf("go go go\n"); 13 else 14 printf("something must be wrong...\n") ; 15 getchar(); 16 } 17 return 0; 18 }
实验四
1 #include<stdio.h> 2 int main (){ 3 double i= 0, sum = 1, max = 0, min = 20000; 4 5 printf("输入今日的开销,直到输入-1终止:\n"); 6 while (i != -1) { 7 scanf("%lf",&i); 8 sum = sum + i; 9 10 if (max < i) 11 max = i; 12 else 13 max = max; 14 if ( min > i && i!= -1) 15 min = i; 16 else 17 min = min; 18 } 19 20 printf("今日累计消费总额:%.1f\n",sum); 21 printf("今日最高一笔开销:%.1f\n",max); 22 printf("今日最低一笔开销:%.1f\n",min); 23 }
实验五
1 #include<stdio.h> 2 int main () 3 { 4 int a, b, c; 5 6 7 while (scanf("%d %d %d",&a,&b,&c) != EOF){ 8 if ( a+b>c && a+c>b && b+c>a ){ 9 if (a == b && b == c) 10 printf("等边三角形\n"); 11 else if (a == b || b == c || a == c) 12 printf("等腰三角形\n"); 13 else if (a*a + b*b == c*c || c*c + b*b == a*a || a*a + c*c == b*b ) 14 printf("直角三角形\n"); 15 else 16 printf("一般三角形\n"); 17 } 18 else 19 printf("不构成三角形\n"); 20 21 } 22 23 24 25 return 0; 26 }
实验六
1 #include<stdio.h> 2 int main (){ 3 int lday, day; 4 int i= 0; 5 srand(time(NULL)); 6 lday = rand()%30 +1; 7 8 9 printf("猜猜2024年11月那一天会是你的幸运日\n开始喽,你只有三次机会,猜吧(1~30): "); 10 11 12 while ( i < 3 ){ 13 scanf("%d",&day); 14 15 if ( day == lday && i <3) 16 printf("哇,猜中了:"); 17 else if (day < lday && i <3) 18 printf("你猜的日期早了\n再猜(1~30):"); 19 else if (day > lday && i <3) 20 printf("你猜的日期晚了\n再猜(1~30):"); 21 22 i++; 23 24 } 25 if ( day != lday && i ==3) 26 printf("次数用光啦,偷偷告诉你,11月你的幸运日是%d号",lday); 27 28 return 0; 29 }
标签:%.,int,else,p1,实验,printf,include From: https://www.cnblogs.com/wrc123/p/18456826