实验任务1
#include <stdio.h> #include <stdlib.h> #include <time.h> #define N 5 #define N1 374 #define N2 465 int main() { system("color E5"); int number; int i; srand( time(0) ); // 以当前系统时间作为随机种子 for(i = 0; i < N; ++i) { number = rand()%(N2 - N1 + 1) + N1; printf("202383290376%04d\n", number); } return 0; }
问题1:解释line17代码的功能:以当前系统时间作为随机种子,随机生成一个374~465的整数
问题2:这个程序的功能是什么:生成4个最后三位随机的数字,随机范围是374~465,前面固定为2023832903760
实验任务2
#include<stdio.h> #include<stdlib.h> int main(void) { system ("color 6F"); char col; while(scanf("%c",&col)!=EOF) { switch(col) { case 'r':printf("stop!\n");break; case 'g':printf("go go go\n");break; case 'y':printf("wait a minute\n");break; defualt :printf("something must be wrong...\n"); } } return 0; }
实验任务3
int main() { system("color 5F"); int shit; int i,j=0; int day; printf("猜猜2023年11月哪一天你会踩到狗屎\n"); printf("开始喽,你有三次机会,猜吧(1~30):"); srand( time(0) ); shit = rand()%31; for(i=1;i<=3;i++) { scanf("%d",&day); if(day>shit) { printf("你猜得晚了,你还踩不到狗屎呢\n"); j++; } else if(day<shit) { printf("你猜得早了,你已经踩过狗屎辣\n"); j++; } else if(day=shit) { printf("哇!踩到狗屎辣\n"); exit(0); } if(i<3) printf("再猜:"); else if(j==3) printf("次数用完辣,偷偷告诉你:11月,你在%d号会踩到狗屎",shit); } return 0; }
实验任务4
#include <stdio.h> #include <stdlib.h> int main(void) { system("color 9F"); int t=1; int i; int n,a; double s; while(scanf("%d %d",&n,&a)!=EOF) { for (i=1;i<=n;i++) { s+=i/(t*a*1.0); t=t*10+1; } printf("n = %d, a = %d, s = %lf\n\n",n,a,s); } return 0; }
实验任务5
#include<stdio.h> #include<stdlib.h> int main() { system ("color B1"); int i = 0; int j = 0; for(i=1;i<=9;i++) { for(j=1;j<=i;j++) { printf("%dx%d = %2d ",j,i,i*j); } printf("\n"); } return 0; }
实验任务6
#include<stdio.h> #include<stdlib.h> int main() { system("color B5"); int n; printf("input n:"); scanf("%d", &n); int m = 2*n - 1; int max = m * 3 + ( m - 1) * 4; for (int i = m ; i > 0; i -= 2) { int width = i * 3 + (i - 1) * 4; int fuck = (max - width) / 2; for (int j=0; j < fuck; j++) printf(" "); for (int j = 0; j < i; j++) { printf(" O "); if (j != i - 1) printf(" "); } printf("\n"); for (int j = 0; j < fuck; j++) printf(" "); for (int j = 0; j < i; j++) { printf("<H>"); if (j != i - 1) printf(" "); } printf("\n"); for (int j = 0; j < fuck; j++) printf(" "); for (int j = 0; j < i; j++) { printf("I I"); if (j != i - 1) printf(" "); } printf("\n\n"); } return 0; }
标签:main,int,++,实验,printf,include,color From: https://www.cnblogs.com/Obrez/p/17767933.html