上机实验作业2
#include <stdio.h> #include <stdlib.h> #include <time.h> #define N 5 int main()/*随机生成五组学号*/ { int grade,number; int i; srand(time(0)); for(i=0;i<N;++i) { grade=rand()%4+2018;/*生成2018-2021的随机数作为年级*/ number=rand()%999+1;/*生成1-999的随机数作为后三位学号*/ printf("%d8330%04d\n",grade,number); } return 0; }
#include <stdio.h> #include <stdlib.h> #include <time.h> int main() { int luckyday=rand(); int i,x; srand(time(0)); luckyday=rand()%30+1; printf("猜猜2022年4月哪一天会是你的lucky day\n"); printf("开始喽,你有三次机会,猜吧(1~30):\n"); for(i=1;i<=3;i++) { scanf("%d",&x); if(x>luckyday) {printf("你猜的日期晚了,你的lucky day已经过啦\n"); if(i!=3) printf("再猜:\n");} if(x<luckyday) {printf("你猜的日期早了,你的lucky day 还没到呢\n"); if(i!=3) printf("再猜:\n");} if(i==3&&x!=luckyday) printf("次数用完啦,偷偷告诉你:4月,你的lucky day是%d\n",luckyday); else if(x==luckyday) {printf("哇,猜中了:-)\n");break;} } return 0; }
#include <stdio.h> int main() { char x; while(scanf("%c",&x)!=EOF) { switch(x) { case 'r':getchar();printf("stop!\n");break; case 'g':getchar();printf("go go go\n");break; case 'y':getchar();printf("wait a minute\n");break; default :getchar();printf("something must be wrong...\n");break; } } return 0; }
#include <stdio.h> #include <math.h> int main() { int n,a,j; double s,fm; while(scanf("%d %d",&n,&a)!=EOF) { fm=0; s=0; for(j=0;j<n;j++) { fm=fm+a*pow(10,j); s=s+(j+1)/fm; } printf("n=%d, a=%d, s=%lf\n",n,a,s); } return 0; }
#include <stdio.h> int main() { int i,j,sum; for(i=1;i<=9;i++) { for(j=1;j<=i;j++) { sum=i*j; printf("%d X %d= %2d ",i,j,sum); } printf("\n"); } return 0; }
#include <stdio.h> int main() { int n,i; printf("input n:"); scanf("%d",&n); for(i=1;i<=n;i++) { printf(" O \n"); printf("<H>\n"); printf("I I\n"); printf("\n"); } return 0; }
#include <stdio.h> int main() { int n,i; printf("input n:"); scanf("%d",&n); for(i=1;i<=n;i++) {printf(" O "); if(i==n) printf("\n");} for(i=1;i<=n;i++) {printf("<H> "); if(i==n) printf("\n");} for(i=1;i<=n;i++) {printf("I I "); if(i==n) printf("\n");} return 0; }
#include<stdio.h>
int main()
{
int row,col,n;
scanf("%d",&n);
for(row=1;row<=n;row++)
{
for(col=1;col<row;col++)
printf(" ");
for(col=1;col<=2*n-(2*row-1);col++)
printf(" O ");
printf("\n");
for(col=1;col<row;col++)
printf(" ");
for(col=1;col<=2*n-(2*row-1);col++)
printf("<H> ");
printf("\n");
for(col=1;col<row;col++)
printf(" ");
for(col=1;col<=2*n-(2*row-1);col++)
printf("I I ");
printf("\n");
}
return 0;
}