实验任务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 - R1 + 1) + R1; printf("20228330%04d\n", number); } return 0; }
截图:
实验任务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,1, &c2,1, &c3,1); printf("c1=%c,c2=%c,c3=%c\n", c1, c2, c3); scanf_s("%lf %lf", &x, &y); printf("x=%lf,y=%lf\n", x, y); return 0; }
截图:
实验任务3
代码:
#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 C, F; while (scanf_s("%lf", &C) != EOF) { F = 9 * C / 5 + 31; printf(" 摄氏度c=% .2f时,华氏度f= % .2f\n", C,F); printf("\n"); } return 0; }
截图:
实验任务4
代码:
截图:
实验任务5
代码:
#include<stdio.h> #include<stdlib.h> #include<time.h> int main() { printf("猜猜2023年4月哪一天会是你的lucky day\n"); int x, y; srand(time(0)); y = rand() % 30 + 1; printf("开始喽,你有3次机会,猜吧(1~30):"); for (int i = 1;; i++) { if (i > 1) printf("再猜(1~30):"); scanf_s("%d", &x); if (x == y) { printf("哇,猜中了:-)\n"); break; } if (x < y) { printf("你猜的日期早了,你的lucky day还没到呢\n"); } else { printf("你猜的日期晚了,你的lucky day已经过啦\n"); } if (i > 2) { printf("次数用完啦。偷偷告诉你:4月,你的lucky day是%d号", y); break; } } system("pause"); return 0; }
截图:
实验任务6
代码:
#include<stdio.h> #include<stdlib.h> int main() { int column=1, line=1,value=1; for (column = 1; column <= 9; column++) { for (line = 1; line <= column; line++) { value = column * line; printf("%d*%d=%d ", line, column,value); } printf("\n"); } system("pause"); return 0; }
截图:
实验任务7
代码:
截图:
标签:lf,截图,int,scanf,实验,printf,include From: https://www.cnblogs.com/gueal/p/17237589.html