task1
源代码
#include<stdio.h> #include<stdlib.h> #include<time.h> #include<math.h> #define N 5 #define R1 663 #define R2 701 int main() { int number, i; srand(time(0)); for (i = 0; i < N; ++i) { number = rand() % (R2 - R1 + 1) + R1; printf("20228330%04d\n", number); } return 0; }
实验结果
task2
源代码
#include<stdio.h> #include<stdlib.h> //#include<math.h> //#include<time.h> //#define N 5 //#define R1 586 //#define R2 701 int main() { double x, y; char c1, c2, c3; int a1, a2, a3; scanf_s("%d%d%d", &a1, &a2, &a3); getchar(); //printf("a1=%d,a2=%d,a3=%d\n", a1, a2, a3); //c1 = getchar(); //c2 = getchar(); //c3 = getchar(); scanf_s("%c%c%c", &c1,1, &c2,1, &c3,1); getchar(); //printf("c1=%c,c2=%c,c3=%c\n", c1, c2, c3); scanf_s("%lf%lf", &x, &y); printf("a1=%d,a2=%d,a3=%d\n", a1, a2, a3); printf("c1=%c,c2=%c,c3=%c\n", c1, c2, c3); printf("x=%lf,y=%lf\n", x, y); return 0; }
实验结果
task3-3
源代码
#include<stdio.h> //#include<stdlib.h> //#include<time.h> #include<math.h> int main() { double c, f; while (scanf_s("%lf", &c) != EOF) { f = (9.0 / 5.0) * c + 32; printf("摄氏度c=%lf时,华氏度f=%lf\n", c, f); } return 0; }
实验结果
task4
源代码
#include<stdio.h> #include<stdlib.h> //#include<time.h> //#include<math.h> int main() { char color; //color = getchar(); //getchar(); while (scanf_s("%c",&color,1) != EOF) { //getchar(); //color = getchar(); switch (color) { case'r':printf("STOP!\n"); break; case'g':printf("GO GO GO!\n"); break; case'y':printf("WAIT A MINUTE!\n"); break; default:printf("something must be wrong!\n"); } getchar(); } return 0; }
实验结果
task5
源代码
#include<stdio.h> #include<stdlib.h> #include<math.h> #include<time.h> #define N 1 #define R1 1 #define R2 30 int main() { int number,i,j; int flag; flag = 1; srand(time(0)); number = rand() % (R2 - R1 + 1); printf("猜猜2023年4月哪一天是你的luckyday\n"); printf("开始喽,你有三次机会,猜吧(1-30):"); for (i = 1; i < 4; ++i) { scanf_s("%d", &j); if (number == j) { printf("哇,你猜中了\n"); flag == 0; continue; } else if (number > j) { printf("你猜的日期早了,你的lucky day还没到呢\n"); printf("再猜:"); continue; } else(number < j); { printf("你猜的日期晚了,你的lucky day已经过了\n"); printf("再猜:"); continue; } } if (flag = 1) printf("次数用完了,偷偷告诉你,4月你的luckyday是%d\n", number); return 0; }
实验结果
task6
源代码
#include<stdio.h> #include<stdlib.h> #include<time.h> #include<math.h> int main() { int i, j, line, column; int value; line = 1; column = 1; value = line * column; scanf_s("%d", &i); for (line = 1; line <= i; line++) { for (column = 1; column <= line; ++column) { //printf("*"); value = line * column; printf("%d x %d = %d\t", column, line, value); //printf("\n"); } printf("\n"); } return 0; }
实验结果
task7
源代码
#include<stdio.h> #include<stdlib.h> #include<time.h> #include<math.h> int main() { int n, i,j,a,line; printf("请输入行数line:"); scanf("%d", &line); n=2*line-1; i=n; while ( i >=0) { for (a = 0; a <=(n- i)/2; a++) { printf("\t"); } for (j = 1; j <= i; j++) { printf(" o \t"); } printf("\n"); for (a = 0; a<=(n- i)/2; a++) { printf("\t"); } for (j = 1; j <= i; j++) { printf(" <H>\t"); } printf("\n"); for (a= 0; a<=(n- i)/2; a++) { printf("\t"); } for (j = 1; j <= i; j++) { printf(" I I\t"); } printf("\n"); printf("\n"); i=i-2; } return 0; }
实验结果
标签:int,number,define,实验,printf,include,getchar From: https://www.cnblogs.com/cjqyyds666666/p/17247223.html