一.任务1
#include <stdio.h> #include <stdlib.h> #include <time.h> #define N 5 #define R1 586 #define R2 701 int main() { int number; int i; srand(time(0)); for (i = 0; i < N; ++i) { number = rand() % (R2 - R2 + 1) + R1; printf("20228330%04d\n", number); } return 0; }
问题:得到586~701之间的任一随机数;使得出一个学号。
二.任务2
#include <stdio.h> int main() { double x, y; char c1, c2, c3; int a1, a2, a3; scanf_s("%d%d%d", &a1, &a2, &a3); printf("a1 = %d, a2 = %d, a3 = %d\n", a1, a2, a3); getchar(); scanf_s("%c%c%c", &c1, &c2, &c3); printf("c1 = %c, c2 = %c, c3 = %c\n", c1, c2, c3); getchar(); scanf_s("%lf,%lf", &x, &y); printf("x = %lf, y = %lf\n", x, y); return 0; }
三.任务3
1)
#include<stdio.h> #include<math.h> int main() { double x, ans; scanf_s("%lf", &x); ans = pow(x, 365); printf("%.2f的365次方:%.2f\n", x, ans); return 0; }
2)
#include<stdio.h> #include<math.h> int main() { double x, ans; while (scanf_s("%lf", &x) != EOF) { ans = pow(x, 365); printf("%.2f的365次方:%.2f\n", x, ans); printf("\n"); } return 0; }
摄氏度华氏度转换
#include<stdio.h> #include<math.h> int main() { double F, C; while (scanf_s("%lf", &C) != EOF) { F = 9 /(double) 5 * C + 32; printf("摄氏度c=%.2f时,华氏度f=%.2f\n", C, F); } return 0; }
四.任务4
#include <stdio.h> int main() { char ans; while (scanf_s("%c", &ans) != EOF) { getchar(); if (ans == 'r') printf("stop!\n"); else if (ans== 'g') printf("go go go\n"); else if (ans == 'y') printf("wait a minute\n"); else printf("something must be wrong...\n"); } return 0; }
五.任务5
#include<stdio.h> int main() { int d,a; d = rand() % 30 + 1; printf("猜猜2023年4月哪一天会是你的lucky day\n"); printf("开始喽,你有三次机会,猜吧(1~30):\n"); scanf_s("%d", &a); if (a == d) { printf("哇,猜中了:-)"); } else { if (a > d) printf("你猜的日期晚了,你的lucky day已经过啦\n"); if (a < d) printf("你猜的日期早了,你的lucky day还没到呢\n"); printf("再猜猜(1~30):\n"); scanf_s("%d", &a); if (a == d) { printf("哇,猜中了:-)"); } else { if (a > d) printf("你猜的日期晚了,你的lucky day已经过啦\n"); if (a < d) printf("你猜的日期早了,你的lucky day还没到呢\n"); printf("再猜猜(1~30):\n"); scanf_s("%d",&a); if (a == d) { printf("哇,猜中了:-)"); } else { if (a > d) printf("你猜的日期晚了,你的lucky day已经过啦\n"); if (a < d) printf("你猜的日期早了,你的lucky day还没到呢\n"); printf("次数用完啦。偷偷告诉你:4月,你的lucky day是%d\n", d); } } } return 0; }
六.任务6
#include<stdio.h> int main() { int i, j; for (i = 1;i <= 9;i++) { for (j = 1;j <= i;j++) { printf("%d*%d=%2d ", j, i, j * i); } printf("\n"); } return 0; }
七.任务7
#include<stdio.h> int main() { int n, i, t; printf("input:"); scanf_s("%d", &n); for (i = 1;i <= n;i++) { for (t = 1;t <= i - 1;t++) printf("\t"); for (t = 1;t <= (n - i) * 2 + 1;t++) printf(" O \t"); printf("\n"); for (t = 1;t <= i - 1;t++) printf("\t"); for (t = 1;t <= (n - i) * 2 + 1;t++) printf("<H>\t"); printf("\n"); for (t = 1;t <= i - 1;t++) printf("\t"); for (t = 1;t <= (n - i) * 2 + 1;t++) printf("I I\t"); printf("\n"); } return 0; }
标签:main,int,scanf,printf,实验,ans,include From: https://www.cnblogs.com/zozominions/p/17238088.html