实验2
1、实验任务1
问题1:以当前系统时间为种子,生成一个随机数
问题2:随机生成一个学号
2、实验任务2
问题1:如果去掉,总价格不会清零,会积累到下一次购买价格中
问题2:跳过循环中continue之后的代码,进入下一循环
3、实验任务3
点击查看代码
#include<stdio.h>
int main() {
printf("请输入字符\n");
char ch;
while ((scanf_s("%c", &ch))!= EOF)
{
if (ch == 'r') {
printf("stop\n");
getchar();
}
else if (ch == 'g')
{
printf("go go go\n");
getchar();
}
else if (ch == 'y')
{
printf("wait a minute\n");
getchar();
}
else
{
printf("some thing must be wrong");
getchar();
}
}

4、实验任务4
点击查看代码
#include<stdio.h>
int main() {
printf("请输入今日开销,直到-1时停止\n");
double expense=0 ;
double total = 0;
double max=0 ;
double min =20000;
while (1)
{
scanf_s("%lf", &expense);
if (expense == -1)
{
printf("今日累计消费总额: %.1lf\n", total);
printf("今日最高一笔开销: %.1lf\n", max);
printf("今日最低一笔开销: %.1lf\n", min);
break;
}
if (expense >= max)
max = expense;
if (expense<= min)
min = expense;
total += expense;
}
return 0;
}

5、实验任务5
点击查看代码
#include <stdio.h>
int main()
{
int a, b, c;
while ((scanf_s("%d %d %d", &a, &b, &c) != EOF)) {
if (a + b > c && a + c > b && b + c > a)
{
if (a == b || a == c || b == c)
{
if (a == b && b == c)
{
printf("等边三角形\n");
}
else { printf("等腰三角形\n"); }
}
else if (a * a + b * b == c * c || a * a + c * c == b * b || b * b + c * c == a * a)
{
printf("直角三角形\n");
}
else
{
printf("普通三角形\n");
}
}
else
{
printf("不能构成三角形\n");
}
}
return 0;
}

6、实验任务6
点击查看代码
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define all 3
int main()
{
int num;
srand(time(NULL));
num = rand() % 30 + 1;
int times = all;
printf("猜猜2025年11月哪一天是你的lucky day \n开始喽,你有 %d 次机会,猜吧(1~30): ", N);
while (times--) {
if (times < 2) printf("再猜(1~30):");
int n;
scanf("%d", &n);
if (n < times) printf("你猜的日期早了,你的 lucky day 在后面哦\n");
else if (n > times) printf("你猜的日期晚了,你的 lucky day 在前面哦\n");
else {
printf("哇,猜中了:)\n");
break;
}
}
if (times < 0) printf("次数用光了。偷偷告诉你,11月你的lucky day 是 %d 号\n", r);
return 0;
}


浙公网安备 33010602011771号