task1.c
问题一:生成1~65中的随机数
问题二:随机生成5个本班学号
task2.c
1 #include <stdio.h> 2 int main() 3 { 4 char colour; 5 printf("请输入交通信号灯的颜色:"); 6 while ((colour = getchar()) != EOF) 7 { 8 switch (colour) 9 { 10 case 'r': 11 printf("stop!\n"); 12 break; 13 case 'g': 14 printf("go go go\n"); 15 break; 16 case 'y': 17 printf("wait a minute\n"); 18 break; 19 default: 20 printf("something must be wrong\n"); 21 } 22 getchar(); 23 } 24 return 0; 25 }
task3.c
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <time.h> 4 int main() 5 { 6 printf("猜猜2024年5月哪一天会是你的lucky day\n"); 7 int luckyday,guess,i; 8 srand(time(0)); 9 luckyday = rand() % 31 + 1; 10 printf("开始喽,你有三次机会,猜吧:"); 11 for (i = 0; i < 3; i++) 12 { 13 scanf("%d", &guess); 14 if (guess == luckyday) 15 { 16 printf("猜中了\n"); 17 return 0; 18 } 19 else if (guess > luckyday) 20 printf("猜晚了\n"); 21 else 22 printf("猜早了\n"); 23 } 24 if (i = 3) 25 printf("次数用完啦,悄悄告诉你,5月你的lucky day是%d号", luckyday); 26 27 return 0; 28 }
task4.c
1 #include <stdio.h> 2 int main() 3 { 4 double s = 0,down=0; 5 int i,n,a; 6 while (scanf("%d%d", &n, &a) != EOF) 7 { 8 for (i = 1; i <= n; i++) 9 { 10 down = 10 * down + (double)a; 11 s += i / down; 12 } 13 printf("s=%lf\n", s); 14 s = 0; 15 down = 0; 16 } 17 return 0; 18 }
task5.c
1 #include <stdio.h> 2 int main() 3 { 4 int column, line, value; 5 for (column = 1; column <= 9; column++) 6 { 7 for (line = 1; line <= column; line++) 8 { 9 value = column * line; 10 printf("%dx%d =%4d ", line, column, value); 11 if (line == column) 12 printf("\n"); 13 } 14 } 15 return 0; 16 }
task6.c
1 #include <stdio.h> 2 int main() 3 { 4 int n,i,j; 5 scanf("%d", &n); 6 for (i=n;i>0;i--) 7 { 8 for (j = 0; j < n - i; j++) 9 { 10 printf(" \t"); 11 } 12 for (j = 0; j < (2 * i - 1); j++) 13 { 14 printf(" O \t"); 15 } 16 printf("\n"); 17 for (j = 0; j < n - i; j++) 18 { 19 printf(" \t"); 20 } 21 for (j = 0; j < (2 * i - 1); j++) 22 { 23 printf("<H>\t"); 24 } 25 printf("\n"); 26 for (j = 0; j < n - i; j++) 27 { 28 printf(" \t"); 29 } 30 for (j = 0; j < (2 * i - 1); j++) 31 { 32 printf("I I\t"); 33 } 34 printf("\n"); 35 36 } 37 return 0; 38 } 39
标签:main,int,编程,luckyday,C语言,++,printf,include,分支 From: https://www.cnblogs.com/1262438226qqcom/p/18121292