任务1
#include <stdio.h> #include <stdlib.h> #include <time.h> #define N 5 #define N1 374 #define N2 465 int main(){ 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; }
line17功能: 输入[N1,N2]之间随机数字
功能:学号尾号随机抽取学生
任务2
#include <stdio.h> int main (){ char m; while(scanf("%c",&m)!=EOF){ if(m=='r') printf("stop!\n"); else if(m=='g') printf("go go go\n"); else if (m=='y') printf("wait a minute\n"); else printf("something must be wrong"); } }
任务3
#include <stdio.h> #include <stdlib.h> int main (){ int a,i=1,n; printf("猜猜哪一天是你的lucky day\n"); printf("开始咯"); a=rand()%30+1; for(i=1;i<=3;i++){ scanf("%d",&n); if(n==a){ printf("猜中了"); break; } if(n>a){ printf("你猜的日期晚了,你的lucky day已经过了\n"); continue; } if(n<a){ printf("你猜的日期早了,你的lucky day还没到呢\n"); continue; } } if(i>3){ printf("次数用完了,你的lucky day是%d",a); } }
实验4
#include <stdio.h> int main (){ int a,n; double t,s; while(scanf("%d",&n)!=EOF&&scanf("%d",&a)){ t=0; s=0; for(int i=1;i<=n;i++){ t=a+t; s=s+i*1.0/t; a=a*10; } printf("%f",s); printf("\n"); } }
任务5
#include <stdio.h> int main (){ int n,i=1,s; scanf("%d",&n); for(i=1;i<=n;i++){ for(int j=1;j<=i;j++){ s=i*j; printf("%dx%d=%d\t",i,j,s); } printf("\n"); } }
实验6
#include <stdio.h> int main (){ int a=1,b=1,c,n,m,i=1; scanf("%d",&n); m=n; for(i=1;i<=n;i++){ for(a=1;a<i;a++){ printf(" "); } for(b=1;b<=2*m-1;b++){ printf(" O "); printf(" "); } printf("\n"); for(a=1;a<i;a++){ printf(" "); } for(b=1;b<=2*m-1;b++){ printf("<H>"); printf(" "); } printf("\n"); for(a=1;a<i;a++){ printf(" "); } for(b=1;b<=2*m-1;b++){ printf("I I"); printf(" "); } printf("\n"); m--; } }
标签:include,int,scanf,实验,printf,go,main From: https://www.cnblogs.com/31wqewq/p/17767929.html