task1.c
#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); } system("pause"); return 0; }
问题1:得到1~65之间的一个随机数
问题2:一次输出5个学号
task2.c
#include<stdio.h> #include<stdlib.h> int main() { char n; while(scanf("%c",&n) != EOF){ 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; } getchar(); } system("pause"); return 0; }
task3.c
#include<stdio.h> #include<stdlib.h> #include<time.h> int main() { int lucky_day; int guess; int cnt; lucky_day = rand()%31+1; for(cnt = 0;cnt<3;++cnt){ scanf("%d",&guess); if(guess == lucky_day) printf("哇,猜中了!\n"); else if(guess < lucky_day) printf("你猜的日期早了,你的lucky_day还没到呢\n"); else printf("你猜的日期晚了,你的lucky_day在前面哦\n"); } if(guess != lucky_day) printf("次数用完了,偷偷告诉你,五月你的lucky_day是:%d\n",lucky_day); return 0; }
task4.c
#include<stdio.h> int main(){ int a,n ,i; double s; while(scanf("%d%d",&a,&n) != EOF){ int e=a; s = 0.0; for(i=1;i<=n;i++) { s+=(double)i/e; e = e*10 +a; } printf("n = %d,a = %d,s = %lf",n,a,s); } return 0; }
task5.c
#include<stdio.h> int main() { int i,j; for(i+1;i<=9;i++) { for(j=1;j<=i;j++) printf("%d*%d=%d\t",j,i,j*i); printf("\n"); } return 0; }
task6.c
#include <stdlib.h> int main() { int n, i, k, j; printf("input n:"); scanf("%d", &n); for (i = 0; i < n; i++) { for (j = 0; j < i; j++) { printf("\t"); } for (k = 2 * (n-i) - 1; k>0; k--) { printf(" O \t"); } printf("\n"); for (j = 0; j < i; j++) { printf("\t"); } for (k = 2 * (n-i) - 1; k>0; k--) { printf("<H>\t"); } printf("\n"); for (j = 0; j < i; j++) { printf("\t"); } for (k = 2 * (n - i) - 1; k > 0; k--) { printf("I I\t"); } printf("\n"); } return 0; }
实验总结:
1、学会使用switch多分支语句
2、知道如何得到一个随机数
标签:include,int,break,++,实验,printf,main From: https://www.cnblogs.com/wangmiao-wm/p/18121244