实验2
内容1:

问题1:rand无法每次运行都生成一个随机数
问题2:随取抽取一位学生的学号
内容2:

问题1:去掉后,下次运行出错,没有令total_price=0
问题2:继续执行continue后面的循环语句
内容3:
#include <stdio.h> int main() { char color; while (scanf(" %c", &color) == 1) { if (color == 'r') { printf("stop!\n"); } else if (color == 'g') { printf("go go go\n"); } else if (color == 'y') { printf("wait a minute\n"); } else { printf("something must be wrong...\n"); } } return 0; }

内容4:
#include <stdio.h> int main() { double x; double total = 0,max=0,min=20000; while (1) { scanf("%lf", &x); if (x == -1) break; total += x; if (x > max) max = x; if (x < min) min = x; } printf("今日累计消费金额: %.1lf 元\n", total); printf("今日最高一笔开销: %.1lf 元\n", max); printf("今日最低一笔开销: %.1lf 元\n", min); return 0; }

内容5:
#include <stdio.h> int main() { int a, b, c; int x, y, z; while (scanf("%d%d%d", &a, &b, &c) != EOF) { if (a + b <= c || a + c <= b || b + c <= a) { printf("不能构成三角形\n"); continue; } x = a * a; y = b * b; z = c * c; if (a == b && b == c) printf("等边三角形\n"); else if (a == b || a == c || b == c) printf("等腰三角形\n"); else if (x + y == z || x + z == y || y + z == x) printf("直角三角形\n"); else printf("普通三角形\n"); } return 0; }

内容6:
#include<stdio.h> #include<stdlib.h> #include<time.h> int main() { int a, b, c=3; srand(time(NULL)); b = rand() % 30 + 1; printf("猜猜2025年11月哪一天是你的 lucky day\n\n"); printf("开始咯,你有三次机会,猜吧(1~30):"); for (int i = 0; i < c; ++i) { scanf("%d", &a); if (a == b) { printf("哇,猜中了;)\n"); break; } if ((a != b) && (a > b)) printf("\n你猜的日期晚了,你的 lucky day在前面哦\n\n"); else if ((a != b) && (a < b)) printf("\n你猜的日期早了,你的 lucky day还没到呢\n\n"); if(i<c-1) printf("再猜(1~30):"); } if(a !=b) printf("次数用光啦。偷偷告诉你,11月你的lucky day是%d号", b); return 0; }

浙公网安备 33010602011771号