实验2
1.问题一:如果没有这行代码srand(time(NULL)),rand 生成的随机数序列会是固定的,失去了 “随机” 的意义。
问题二:随机生成学号
2.问题一:total_price = 0; 去掉会使上一次购买金额加到此次上
问题二:continue语义,在该次程序运行中用户输入不满足if()中的条件时跳出该次运行,重新开始运行程序

1 #include <stdio.h> 2 int main() { 3 char ch; 4 while (scanf("%c", &ch) != EOF) { 5 getchar(); 6 if (ch == 'r') 7 printf("stop!\n"); 8 else if (ch == 'g') 9 printf("go go go\n"); 10 else if (ch == 'y') 11 printf("wait a minute\n"); 12 else 13 printf("something must be wrong...\n"); 14 } 15 return 0; 16 }

1 #include <stdio.h> 2 int main() { 3 float num=0.0,cost,maxcost=0.0,mincost=20000.0; 4 printf("输入今日开销,直到输出-1终止:\n"); 5 while (scanf("%f", &cost)!=EOF) { 6 if (cost==-1) 7 break; 8 num = cost + num; 9 if (cost > maxcost) 10 maxcost = cost; 11 if (cost < mincost) 12 mincost = cost; 13 } 14 printf("今日累计消费总额:%.1f\n", num); 15 printf("今日最高一笔开销:%.1f\n", maxcost); 16 printf("今日最低一笔开销:%.1f\n", mincost); 17 return 0; 18 }

1 #include <stdio.h> 2 int main() { 3 int a, b, c; 4 while (scanf("%d %d %d", &a, &b, &c) != EOF) { 5 if (a + b > c && a + c > b && b + c > a) { 6 if (a == b && b == c) 7 printf("等边三角形"); 8 else if ((a * a + b * b == c * c)|| (a * a + c * c == b * b) || (b * b + c * c == a * a)) 9 printf("直角三角形"); 10 else if (a == b || a == c || b == c) 11 printf("等腰三角形"); 12 else 13 printf("普通三角形"); 14 }else 15 printf("不能构成三角形"); 16 } 17 return 0; 18 }

1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<time.h> 4 int main() { 5 srand(time(NULL)); 6 int i,n,num = rand() % 30 + 1; 7 printf("猜猜2025年11月哪天是你的 lucky day\n"); 8 printf("开始喽,你有三次机会,猜吧(1~30):"); 9 for (i = 0; i < 3; i++) { 10 scanf("%d", &n); 11 if (n == num) { 12 printf("哇,猜中了:"); 13 return 0; 14 } 15 else if(n > num) 16 printf("你猜的日期晚了,你的 lucky day在前面哦\n"); 17 else 18 printf("你猜的日期早了,你的 lucky day还没到呢\n"); 19 if (i < 2) 20 printf("再猜(1~30):"); 21 } 22 printf("次数用光啦。偷偷告诉你,11月你的lucky day是%d号\n", num); 23 return 0; 24 }