task1:
问题1 随机数求余后结果为1,生成0397到0476中的随机数
问题2 随机数求余后结果为0,生成0001到0021中的随机数
问题3 随机生成5个不同的学号
task2:
实验3:
task4:
1 #include <stdio.h> 2 int main() 3 { 4 double x,sum,max,min; 5 sum = 0; 6 max = 0; 7 min = 10000; 8 printf("输入今日开销,直到输入-1停止\n"); 9 while (scanf_s("%lf", &x)) { 10 if (x > 0 && x <= 10000) { 11 sum = sum + x; 12 if (x > max) max = x; 13 if (x < min) min = x; 14 } 15 else if(x = -1) 16 break; 17 } 18 printf("今日累计消费总额:%.1lf\n", sum); 19 printf("今日最高一笔开销:%.1lf\n", max); 20 printf("今日最小一笔开销:%.1lf\n", min); 21 22 return 0; 23 24 25 }
task5:
1 #include <stdio.h> 2 #include<stdlib.h> 3 int main() { 4 int a, b, c; 5 while (scanf_s("%d%d%d", &a, &b, &c) != EOF) { 6 if (a + b <= c || a + c <= b || b + c <= a) 7 printf("不能构成三角形"); 8 else { 9 if ((a * a + b * b == c * c) || (b * b + c * c == a * a) || (a * a + c * c == b * b)) 10 printf("直角三角形"); 11 else if ((a == b) || (b == c) || (c == a)) { 12 if (a == b && b==c) 13 printf("等边三角形"); 14 else 15 printf("等腰三角形"); 16 } 17 else 18 printf("普通三角形"); 19 } 20 21 } 22 23 24 system("pause"); 25 return 0; 26 } 27
task6
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<time.h> 4 5 int main() { 6 int lucky day, n,ans; 7 n=3; 8 lucky day = rand() % 30 + 1; 9 srand(time(NULL)); 10 11 printf("猜猜2024年11月哪一天会是你的lucky day 开始喽,你有三次机会 猜吧:"); 12 while (n > 0) { 13 scanf_s("%d", &ans); 14 if (ans == lucky day) 15 printf("哇 猜中了");break: 16 else if (ans < lucky day) 17 printf("你猜的日期早了,你的 lucky day还没到呢\n"); 18 else 19 printf("你猜的日期晚了,你的lucky day在前面\n"); 20 n = n - 1; 21 if (n > 0) 22 printf("再猜"); 23 else 24 printf("次数用光了,偷偷告诉你,你的lucky day是%d", lucky day); 25 } 26 system("pause"); 27 return 0; 28 29 }
标签:min,int,编程,lucky,循环,printf,include,day,分支 From: https://www.cnblogs.com/sunhope/p/18454741