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()%500+1; printf("20228329%04d\n",number); } return 0; }
1、限制范围在1~500之间
2、随机取学号
task2
#include<stdio.h> #include<stdlib.h> #include<time.h> int main() { int a,i,j; srand(time(0)); a=rand()%30+1; printf("猜猜2022年11月哪一天会是你的lucky day\n"); printf("开始咯,你有三次机会哦(1~30):"); scanf("%d",&i); for(j=1;j<=3;j++){ if(i<a){ printf("你猜的日期早了,你的lucky day还没到哦~\n"); if(j<=2) { printf("再猜哦~:"); scanf("%d",&i);} else printf("次数用完啦,偷偷告诉你,你的lucky day是:%d",a); } else if(i==a){ printf("哇,猜中了~"); j=4; } else { printf("你猜的日期晚了,你的lucky day已经过咯哦~\n"); if(j<=2) { printf("再猜哦~:"); scanf("%d",&i);} else printf("次数用完啦,偷偷告诉你,你的lucky day是:%d",a); } } return 0; }
task3
#include<stdio.h> int main() { char ans; while(scanf("%c",&ans)!=EOF){ switch(ans){ case 'r':printf("stop\n");getchar();break; case 'y':printf("wait a minute\n");getchar();break; case 'g':printf("go go go\n");getchar();break; default:printf("something must be wrong\n");getchar();break; } } return 0; }
task4
#include<stdio.h> int main() { int a,n,i; double s,x1,x2; while(scanf("%d%d",&n,&a)!=EOF){ x1=1; x2=a; for(i=1,s=0;i<=n;i++){ s=s+x1/x2; x1=x1+1; x2=x2*10+x2; } printf("n=%d,a=%d,s=%.6f\n",n,a,s); } return 0; }
task5
#include<stdio.h> int main() { int line,a,s,i; a=1; scanf("%d",&line); for(;a<=line;a++){ for(i=1;i<=a;i++){ s=i*a; printf("%d*%d=%d\t",i,a,s); } printf("\n"); } return 0; }
task6
#include<stdio.h> int main() { int i,j,k,n; scanf("%d",&n); for(i=1;i<=n;i++){ for(j=1;j<i;j++){ printf(" \t"); } for(j=1;j<=2*(n-i)+1;j++){ printf(" O \t"); } printf("\n"); for(j=1;j<i;j++){ printf(" \t"); } for(j=1;j<=2*(n-i)+1;j++){ printf("<H>\t"); } printf("\n"); for(j=1;j<i;j++){ printf(" \t"); } for(j=1;j<=2*(n-i)+1;j++){ printf("I I\t"); } printf("\n"); printf("\n"); } return 0; }
1、需要2*(n-i)+1个小人
2、i个\t
标签:include,int,scanf,实验,printf,main,getchar From: https://www.cnblogs.com/dubei/p/16808010.html