实验任务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; }View Code
问题一 line17是使随机数控制在374到465之间
问题二 功能是随机生成5个0374到0465的学号
实验任务2
#include<stdio.h> int main() { char n; while(scanf("%c",&n)!=EOF){ getchar(); switch(n){ case'y':printf("wait a minute\n");break; case'g':printf("go go go\n");break; case'r':printf("stop!\n");break; default :printf("something must be wrong...\n");break; }} return 0; }View Code
实验任务3
#include<stdio.h> #include<stdlib.h> #include<math.h> int main() { int n,i,m; n=rand()%30; printf("猜猜2023年11月那一天会是你的lucky day\n"); printf("开始喽,你有三次机会,猜吧(1~30):"); for(i=1;;i++){ scanf("%d",&m); if(n==m){ printf("哇,猜中了:-)\n"); break; } else{ if(m>n) printf("你猜的日期晚了,你的lucky day已经过啦\n再猜(1~30):"); else printf("你猜的日期早了,你的lucky day还没到呢\n再猜 (1~30):"); } if(i==3){ printf("次数用完啦,偷偷告诉你:11月,你的lulcky day是%d号",n); break; } } return 0; }View Code
实验任务4
#include<stdio.h> #include<stdlib.h> int main() { int a,n,i,weishu=1; double up,down,s; while(scanf("%d%d",&n,&a)!=EOF){ weishu=1; s=0; for(i=1;i<=n;i++){ up=i*1.0; down=1.0*a*weishu; s=1.0*up/down+s; weishu=weishu*10+1; } printf("n=%d,a=%d,s=%lf",n,a,s); } return 0; }View Code
实验任务5
#include<stdio.h> int main() { int c,line,v; while(line<=9){ c=1; while(c<=line){ v=c*line; printf("%dx%d= %d ",c,line,v); c++; } printf("\n"); line++; } return 0; }View Code
实验任务6
1 #include<stdio.h> 2 #include<stdlib.h> 3 int main() 4 { 5 int i,l,n=1,k=0,s; 6 scanf("%d",&l); 7 for(i=2*l-1;1<=i;i=i-2){ 8 k++; 9 for(s=1;s<=k;s++){ 10 printf("\t"); 11 } 12 for(n=1;n<=i;n++){ 13 printf(" O\t"); 14 } 15 printf("\n"); 16 for(s=1;s<=k;s++){ 17 printf("\t"); 18 } 19 for(n=1;n<=i;n++){ 20 printf("<H>\t"); 21 } 22 printf("\n"); 23 for(s=1;s<=k;s++){ 24 printf("\t"); 25 } 26 for(n=1;n<=i;n++){ 27 printf("I I\t"); 28 } 29 printf("\n"); 30 } 31 system("pause"); 32 return 0; 33 }View Code
标签:main,int,编程,C语言,break,View,printf,include,分支 From: https://www.cnblogs.com/xaiye00/p/17767935.html