实验任务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; }
实验任务2
#include<stdio.h> int main() { char n; while(scanf("%c",&n)!=EOF) { getchar(); switch(n) { 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; } } return 0; }
实验任务3
#include<stdio.h> #include<math.h> #include<stdlib.h> int main() { int n,i,x; n=rand()%30; printf("gusee which day is your lucky day\n"); for(i=1;i<=3;i++) { scanf("%d",&x); if(x==n) { printf("ok,it's your lucky day\n"); break; } else{ if(x>n) printf("late\n"); else printf("early\n"); } if(i==3) printf("the right answer is %d",n); } return 0; }
实验任务4
#include<stdio.h> #include<stdlib.h> int main() { int i,n,x,a; double s; while(scanf("%d%d",&n,&a)!=EOF){ x=0; s=0; for(i=1;i<=n;i++) { x=x*10+a; s=s+1.0*i/x; } printf("n=%d,a=%d,s=%f\n",n,a,s); } return 0; }
实验任务5
#include<stdio.h> int main() { int i,j,ans; for(i=1;i<=9;i++) { for(j=1;j<=i;j++) { ans=i*j; printf("%dx%d = %2d ",j,i,ans); if(i==j) { printf("\n"); } } } return 0; }
实验任务6
#include<stdio.h> int main() { int n; scanf("%d",&n); int i,j,k; j=0; for(i=2*n-1;i>0;i=i-2){ for(j=0;j<(2*n-i-1)/2;j++){ printf("\t");} for(k=1;k<=i;k++){ printf(" O \t"); if(k==i) printf("\n");} for(j=0;j<(2*n-i-1)/2;j++){ printf("\t");} for(k=1;k<=i;k++){ printf("<H>\t"); if(k==i) printf("\n");} for(j=0;j<(2*n-i-1)/2;j++){ printf("\t");} for(k=1;k<=i;k++){ printf("I I\t"); if(k==i) printf("\n");} } return 0; }
标签:include,int,break,实验,printf,main From: https://www.cnblogs.com/PomPomDyx/p/17767932.html