//test1.c #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;//作用:生成学号后三位在586~701的随机整数 printf("20228330%04d\n"); } return 0; }//该程序的作用是生成2022级16~18班的5位随机同学的学号
问题1:解释line18代码 number = rand() % (R2 - R1 + 1) + R1; 实现的功能
作用:生成学号后三位在586~701的随机整数
问题2:这个程序的功能是什么?
该程序的作用是生成2022级16~18班的5位随机同学的学号
//test2.c #include <stdio.h> int main() { double x, y; char c1, c2, c3; int a1, a2, a3; scanf("%d%d%d", &a1, &a2, &a3);//scanf输入变量前未加地址运算符 printf("a1 = %d,a2 = %d,a3 = %d\n", a1, a2, a3); scanf("%c%c%c", &c1, &c2, &c3); printf("c1 = %c,c1 = %c,c3 = %c\n", c1, c2, c3); scanf("%lf%lf", &x, &y);//scanf输入浮点型变量格式应为"%lf",第二个变量输入时未加l printf("x = %lf,y = %lf\n", x, y); return 0; }
//test3_2.c #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; }
//test3_3.c #include <stdio.h> #include <math.h> int main() { double C, F; while (scanf_s("%lf", &C) != EOF) { F = 9 * C /5 + 32; printf("摄氏度c = %.2f时,华氏度f = %.2f ", C, F); printf("\n"); } return 0; }
//test4.c #include <stdio.h> int main() { char color; while (scanf_s("%c",&color) != EOF) { getchar(); if (color == 'r' || color == 'y' || color == 'g') { if (color == 'r') printf("stop!\n"); else if (color == 'g') printf("go go go\n"); else if (color == 'y') printf("wait a minate\n"); } else printf("something must be wrong...\n"); } return 0; }
//test4_2(方法二) #include <stdio.h> int main() { char color; while(scanf_s("%c", &color) != EOF) { 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"); break; } } return 0; }
//test5.c #include<stdio.h> #include<stdlib.h> #include<time.h> int main() { int luckyday,day, i; srand(time(0)); luckyday = rand() % 30 + 1; printf("猜猜2023年4月哪一天会是你的lucky day\n"); printf("开始喽,你有三次机会,猜吧(1~30): "); for (i = 1; i <= 3; ++i) { scanf_s("%d", &day); if (day < luckyday) { printf("你猜的日期早了,你的luckyday还没到呢\n"); printf("再猜(1~30):"); continue; } else if (day > luckyday) { printf("你猜的日期晚了,你的luckyday已经过啦\n"); printf("再猜(1~30):"); continue; } else printf("哇,猜中了:_\n"); break; } printf("\n"); printf("次数用完啦。偷偷告诉你:4月,你的luckyday是%d", luckyday); return 0; }
//test6.c #include <stdio.h> int main() { int line, column, value; for(line=1;line<=9;++line) { for (column = 1; column <= line; ++column) { value = line * column; printf("%dx%d = %d ",column,line,value); } printf("\n"); } return 0; }
//test7.c #include <stdio.h> int main() { int n,i,j; printf("input n: "); scanf_s("%d", &n); for (j = n; j >= 1; --j) { for (i = 1; i <= (n-j); ++i) printf(" \t"); for (i = 1; i <= (2 * j - 1); ++i) printf(" o \t"); for (i = 1; i <= (n-j); ++i) printf(" \t"); printf("\n"); for (i = 1; i <= (n-j); ++i) printf(" \t"); for (i = 1; i <= (2 * j - 1); ++i) printf("<H>\t"); for (i = 1; i <= (n-j); ++i) printf(" \t"); printf("\n"); for (i = 1; i <= (n - j); ++i) printf(" \t"); for (i = 1; i <= (2 * j - 1); ++i) printf("I I\t"); for (i = 1; i <= (n - j); ++i) printf(" \t"); printf("\n"); } return 0; }
当输入为n时:
第i行,需要打印多少个字符小人
第i行,需打印(2*(n-i+1)-1)个字符小人
第i行,前面需要打印多少空白(需要使用多少个 \t )
第i行,前面需要打印(i-1)*3个空白(需要使用(i-1)个\t)
标签:main,实验报告,int,scanf,color,李湘楠,printf,202113020023,include From: https://www.cnblogs.com/gfzxtywgz/p/17230936.html