實驗任務1
#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()%65+1; printf("20238331%04d\n",number); } return 0; }
line 15程式碼功能是在1-66間隨機一個數輸出
程式功能是隨機抽人
實驗任務2
#include<stdio.h> #include<stdlib.h> int main(){ char a; while (scanf ("%c",&a)!=EOF) { switch (a){ 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; } getchar(); } system ("pause"); return 0; }
實驗任務3
#include <stdio.h> #include <stdlib.h> int main(){ int number, a; int i; number = rand()%30+1; printf("猜猜2024年5月哪一天會是你的lucky day \n"); printf("開始嘍,你有三次機會,猜吧(1-31):"); for(i=1;i<=2;++i){ scanf ("%d", &a); if(a==number){ printf("哇,猜中了"); system ("pause"); return 0; }else if(a>number){ printf("你猜的日期晚了,你的lucky day在前面哦\n"); }else if(a<number){ printf("你猜的日期早了,你的lucky day還沒到呢\n"); } printf("再猜(1-31):"); } scanf ("%d", &a); if(a==number){ printf("哇,猜中了"); system("pause"); return 0; }else if(a>number){ printf("你猜的日期晚了,你的lucky day在前面哦\n"); }else if(a<number){ printf("你猜的日期早了,你的lucky day還沒到呢\n"); } printf("次數用完了,偷偷告訴你,你的lucky day是%d號",number); system ("pause"); return 0; }
實驗任務4
#include <stdio.h> #include <stdlib.h> int main(){ int i,j, n, a,b; while(scanf("%d%d",&n,&a)!=EOF) { double s=0; for(i=1;i<=n;i++){ b=0; for(j=1;j<=i;j++){ b=b*10+1; } s+=1.0*i/(a*b); } printf("n=%d, a=%d,s=%f\n", n, a, s); } system("pause"); return 0; }
實驗任務5
#include <stdio.h> #include <stdlib.h> int main(){ int i,j; for(i=1;i<=9;i++){ for (j=1;j<=i;j++){ printf("%d*%d=%2d ",j,i,i*j); } printf("\n"); } system("pause"); return 0; }
實驗任務6
#include <stdio.h> #include <stdlib.h> int main(){ int i,j,n; printf("input n:"); scanf ("%d",&n); for (i=n;i>0;i--){ for(j=1;j<=n-i;j++){ printf(" "); } for (j=1;j<=2*i-1; j++){ printf(" o \t"); } printf("\n"); for(j=1;j<=n-i;j++){ printf(" "); } for (j=1;j<=2*i-1;j++){ printf("<H>\t"); } printf("\n"); for(j=1;j<=n-i;j++){ printf(" "); } for (j=1;j<=2*i-1;j++){ printf("I I\t"); } printf("\n"); } system ("pause"); return 0; }