//task1
#include <stdio.h> #include <stdlib.h> #include <time.h> #define N 5 int main() { int number; int i; srand( time(0) ); for(i = 0; i < N; ++i){ number = rand()%65 + 1; printf("20238331%04d\n",number); } system("pause"); return 0; }
Q1:随机生成1~65之间的数
Q2:随机生成5个学号
task2
#include <stdio.h> #include <stdlib.h> int main() { 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; default:printf("something must be wrong...\n");break; } getchar(); } system("pause"); return 0; }
task3
#include <stdio.h> #include <stdlib.h> #include <time.h> int main() { int lucky_day; int guess; int cnt; srand( time(0) ); lucky_day = rand()%31 +1; printf("猜猜2024年5月哪一天会是你的lucky_day\n"); printf("开始喽,你有三次机会,猜吧(1~31):"); for(cnt = 0;cnt < 3; ++cnt){ scanf("%d",&guess); if(guess == lucky_day){ printf("哇,猜中了:-)\n"); system("pause"); return 0; } if(guess > lucky_day) {printf("你猜的日期晚了,你的lucky_day在前面哦\n"); printf("再猜(1~31):");} if(guess < lucky_day) {printf("你猜的日期早了,你的lucky_day还没到呢\n"); printf("再猜(1~31):");} }printf("次数用完啦。偷偷告诉你,5月你的lucky_day是"); printf("%d",lucky_day); printf("号\n"); system("pause"); return 0; }
task4
#include <stdio.h> #include <stdlib.h> #include <math.h> int main() { int n,a; double s; int down; double i; while(scanf("%d%d",&n,&a)!= EOF){ s = 0.0; printf("n = %d, a = %d",n,a); down = a; for(i = 1;i <= n;++i){ s = s + 1.0*i/down; down = down + pow(10,i) * a; } printf(",s = %lf\n",s); } system("pause"); return 0; }
task5
#include <stdio.h> #include <stdlib.h> int main() { int i,j; for(i = 1;i<10;++i){ for(j = 1;j<i+1;++j){ printf("%d×%d= %d ",j,i,i*j); } printf("\n"); } system("pause"); return 0; }
task6
#include <stdio.h> #include <stdlib.h> int main() { int n,i,j,k; printf("input n:"); scanf("%d",&n); for(i=0;i<n;++i){ for (j=1;j<=i;++j) printf("\t"); for(k=2*(n-i)-1;k>0;--k) printf(" O\t"); printf("\n"); for(j=1;j<=i;++j) printf("\t"); for(k=2*(n-i)-1;k>0;--k) printf(" <H>\t"); printf("\n"); for(j=1;j<=i;++j) printf("\t"); for(k=2*(n-i)-1;k>0;--k) printf(" I I\t"); printf("\n");} system("pause"); return 0; }
标签:main,int,lucky,实验,printf,include,day From: https://www.cnblogs.com/zhaozhimo/p/18134009