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; }
问题一:line15的作用是为了控制所输出的数的数值大小在1~65之间;
问题二:该程序是为了提供介于1和65之间的随机数,一共有4位,其中前两位用0替代。
task2
#include<stdio.h> int main() { char color; while((color = getchar())!=EOF) { if(color == 'r') printf("stop!\n"); else if(color == 'g') printf("go go go\n"); else if(color == 'y') printf("wait a minute\n"); else printf("something must be wrong\n"); getchar(); } 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年哪一天会是你的lucky_day \n开始喽,你有三次机会,猜吧(1~31) : "); //随机生成lucky_day for(cnt = 1;cnt<=3;++cnt) //猜lucy_day { scanf("%d",&guess); if(guess < lucky_day) printf("你猜的日期早了,你的lucky day还没有到呢\n再猜(1~31): "); else if(guess > lucky_day) printf("你猜的日期晚了,你的lucky day在前面哦\n再猜(1~31): "); else { printf("哇,猜中了:-)"); return 0; } if(cnt == 3) printf("次数用完啦。偷偷告诉你,5月你的lucky_day是%02d号",lucky_day); } system("pause"); return 0; }
task4
#include<stdio.h> #include<stdlib.h> int main() { int a,n,d,i; float s,j; while(scanf("%d%d",&n,&a)!=EOF){ d = a; for(i=1;i<=n;i++){ j=1.0*i/d; s +=j; d =d*10+a; } printf("n = %d , a = %d , s = %f\n",n,a,s); } return 0; }
task5
#include<stdio.h> #include<stdlib.h> int main() { int i,j; for(i=1;j<=9;i++) { for(j=1;j<=i;j++) printf("%d*%d=%2d ",i,j,i*j); printf("\n"); } return 0; }
task6
#include<stdio.h> #include<stdlib.h> int main() { int n,a=0; printf("input n: "); scanf("%d",&n); for(;n>=1;n=n-1) { for(int m=1;m<=a;m=m+1) { printf("\t"); } for(int i=1;i<=2*n-1;i=i+1) { printf(" O \t"); } printf("\n"); for(int m=1;m<=a;m=m+1) { printf("\t"); } for(int j=1;j<=2*n-1;j=j+1) { printf("<H>\t"); } printf("\n"); for(int m=1;m<=a;m=m+1) { printf("\t"); } for(int b=1;b<=2*n-1;b=b+1) { printf("I I\t"); } printf("\n"); a=a+1; } system("pause"); return 0; }
标签:main,int,编程,lucky,C语言,printf,include,day,分支 From: https://www.cnblogs.com/ajybky/p/18133791