实验任务1 task1.c
#include<stdio.h> #include<stdlib.h> #include<time.h> #define R2 701 #define N 5 #define R1 586 int main() { int number; int i; srand( time(0) );//以当前系统时间作为随机种子 for(i = 0; i < N; ++i) { number = rand() % (R2 - R1 + 1) + R1; printf("20228330%04d\n", number); } return 0; }
实验任务2 task2.c
#include<stdio.h> int main() { double x, y; char c1, c2, c3; int a1, a2, a3; scanf("%d%d%d",&a1,&a2,&a3); printf("a1 = %d, a2 = %d, a3 = %d\n",a1,a2,a3); scanf("%c%c%c",&c1, &c2, &c3); printf("c1 = %c, c2 = %c, c3 = %c\n", c1, c2, c3); scanf("%lf%lf", &x, &y); printf("x = %lf, y = %lf\n",x,y); return 0; }
实验任务3 task3_1.c
#include<stdio.h> #include<math.h> int main() { double x, ans; scanf("%lf", &x); ans = pow(x,365); printf("%.2f的365次方:5.2f\n", x, ans); return 0; }
task3_2.c
#include<stdio.h> #include<math.h> int main() { double x, ans; while(scanf("%lf", &x) != EOF) { ans = pow(x, 365); printf("%.2f的365次方:%.2f\n", x, ans); printf("\n"); } return 0; }
task3_3.c
#include<stdio.h> #include<math.h> int main() { int c; double f,x; while(scanf_s("%d", &c)) { f = 9.0 / 5 * c + 32; x = c; printf("摄氏度c=%.2lf时,华氏度f=%.2lf", x, f); printf("\n"); } system("pause"); return 0; }
实验任务4 task4.c
#include<stdio.h> int main() { char light; while(scanf("%c",&light)!=EOF) { getchar(); switch(light) { 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; }
实验任务5 task5.c
#include<stdio.h> #include<stdlib.h> #include<time.h> #define N 3 #define R1 1 #define R2 30 int main() { int n1,n2,i,flag; srand(time(0)); flag=0; n1 = rand()%(R2-R1+1)+R1; printf("猜猜2023年4月哪一天会是你的lucky day\n"); printf("开始喽,你有三次机会,猜吧(1-30):"); for(i=1;i<=N;i++) { scanf("%d", &n2); if(n2==n1){ printf("哇,猜中了:-\n"); break; } else if(n2>n1) printf("你猜的日期晚了,你的lucky day已经过啦\n"); else printf("你才的日期早了,你的lucky day还没到呢\n"); printf("再猜(1-30):"); flag++; } if(flag==3) printf("次数用完啦,偷偷告诉你:4月,你的lucky day是%d号\n",n1); return 0;
}
实验任务6 task6.c
#include<stdio.h> int main() { int line,column; for(line=1;line<=9;line++){ for(column=1;column<=line;column++){ printf("%d*%d=%d\t",column,line,line*column); } printf("\n"); } return 0; }
实验任务7 task6.cp
#include<stdio.h> #include<stdlib.h> int main() { int n; printf("input n:"); scanf("%d",&n); for(int i=n;i>0;i--) { for(int j=0;j<n-i;j++) { printf("\t"); } for(int k=0;k<2*i-1;k++) { printf(" O \t"); } printf("\n"); for(int j=0;j<n-i;j++) { printf("\t"); } for(int k=0;k<2*i-1;k++) { printf("I I\t"); } printf ("\n"); } return 0; }
标签:include,return,int,scanf,实验,printf,main From: https://www.cnblogs.com/changdudingqing/p/17234050.html