实验任务1
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <time.h> 4 #define N 5 5 #define R1 586 6 #define R2 701 7 int main() 8 { 9 int number; 10 int i; 11 srand( time(0) ); 12 for(i = 0; i < N; ++i) 13 { 14 number = rand() % (R2 - R1 + 1) + R1; 15 printf("20228330%04d\n", number); 16 } 17 return 0; 18 }
问题1:使number随机取得R1到R2的一个整数
问题2:随机抽取五名学号尾数在587到701的幸运同学
实验任务2
1 #include <stdio.h> 2 int main() 3 { 4 double x, y; 5 char c1, c2, c3; 6 int a1, a2, a3; 7 8 //scanf("%d%d%d", a1, a2, a3); 9 scanf("%d%d%d", &a1, &a2, &a3); 10 printf("a1 = %d, a2 = %d, a3 = %d\n", a1,a2,a3); 11 12 scanf("%c%c%c", &c1, &c2, &c3); 13 printf("c1 = %c, c2 = %c, c3 = %c\n", c1, c2, c3); 14 15 //scanf("%f,%lf", &x, &y); 16 scanf("%lf%lf", &x, &y); 17 printf("x = %f, y = %lf\n",x, y); 18 19 return 0; 20 }
实验任务3
task3_21 #include <stdio.h> 2 #include <math.h> 3 int main() 4 { 5 double x, ans; 6 while(scanf("%lf", &x) != EOF) 7 { 8 ans = pow(x, 365); 9 printf("%.2f的365次方: %.2f\n", x, ans); 10 printf("\n"); 11 } 12 }
task3_3
1 #include <stdio.h> 2 #include <math.h> 3 int main() 4 { 5 double x, ans; 6 while(scanf("%lf", &x) != EOF) 7 { 8 ans = 1.8*x + 32; 9 printf("摄氏度c = %.2f时,华氏度f = %.2f\n", x, ans); 10 printf("\n"); 11 } 12 }
实验任务4
#include <stdio.h> int main() { char x; while(scanf("%lc", &x) != EOF) { switch(x) { case 'y':printf("wait a minute\n");break; case 'g':printf("go go go\n");break; case 'r':printf("stop!\n");break; case '\n':break; default:printf("something must be wrong...\n");break; } } return 0; }
实验任务5
1 #include <stdio.h> 2 #include <time.h> 3 #include <stdlib.h> 4 int main() 5 { 6 int luck,guess,i; 7 srand( time(0) ); 8 luck = rand() % 30 + 1; 9 printf("猜猜2023年4月哪一天会是你的lucky day\n\n"); 10 printf("开始喽,你有三次机会,猜吧(1~30):"); 11 scanf("%d",&guess); 12 if(luck==guess) 13 printf("哇,猜中了:-)"); 14 else 15 { 16 if(guess>luck) 17 printf("你猜的日期晚了,你的lucky day已经过啦\n\n"); 18 else 19 printf("你猜的日期早了,你的lucky day还没到呢\n\n"); 20 for(i=1;i<=2;i++) 21 { 22 printf("再猜(1~30):"); 23 scanf("%d",&guess); 24 if(luck==guess) 25 { 26 printf("哇,猜中了:-)");return 0; 27 } 28 if(guess>luck) 29 printf("你猜的日期晚了,你的lucky day已经过啦\n\n"); 30 else 31 printf("你猜的日期早了,你的lucky day还没到呢\n\n"); 32 } 33 printf("\n次数用完啦,偷偷告诉你:4月,你的lucky day是%d号",luck); 34 } 35 return 0; 36 }
实验任务6
1 #include <stdio.h> 2 int main() 3 { 4 int i,j; 5 for(i=1;i<=9;i++) 6 { 7 for(j=1;j<=i;j++) 8 { 9 printf("%dx%d=%d\t",j,i,j*i); 10 } 11 printf("\n"); 12 } 13 return 0; 14 }
实验任务7
1 #include <stdio.h> 2 int main() 3 { 4 int i,j,n; 5 printf("input n:"); 6 scanf("%d",&n); 7 for(i=n;i>=1;i--) 8 { 9 for(j=1;j<=(n-i);j++) 10 { 11 printf(" \t"); 12 } 13 for(j=1;j<=(2*i-1);j++) 14 { 15 printf(" 0 \t"); 16 }printf("\n"); 17 for(j=1;j<=(n-i);j++) 18 { 19 printf(" \t"); 20 } 21 for(j=1;j<=(2*i-1);j++) 22 { 23 printf("<H>\t"); 24 }printf("\n"); 25 for(j=1;j<=(n-i);j++) 26 { 27 printf(" \t"); 28 } 29 for(j=1;j<=(2*i-1);j++) 30 { 31 printf("I I\t"); 32 }printf("\n"); 33 } 34 return 0; 35 }
标签:main,编程,int,scanf,输入输出,lucky,C语言,printf,include From: https://www.cnblogs.com/dl123/p/17223507.html