Task1
#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() % 500 + 1; printf("20228329%04d\n", number); } return 0; }
随机生成一个范围在1~500以内的整数
随机生成5个同学的学号
Task2
#include<stdio.h> #include<stdlib.h> int main() { int i = 1,s =0; int number; int x; number = rand() % 30 + 1; printf("猜猜2022年11月哪一天会是你的lucky day\n开始喽,你有三次机会,猜吧(1~30):"); for (; i <= 3; i++) { s++; scanf_s("%d", &x); if (x != number) { if (x < number) printf("你猜的日期早了,你的lucky day还没到呢\n"); else printf("你猜的日期晚了,你的lucky day已经过啦\n"); } else { printf("哇,猜中了\n"); break; } if (i < 3) printf("再猜(1~30):"); } if (s = 3) { printf("次数用完啦,偷偷告诉你:11月你的lucky day是:%d", number); } return 0; }
Task3
#include<stdio.h> #include<stdlib.h> int main() { char ch; do { ch = getchar(); if (ch == 'r') printf("stop!\n"); else if (ch == 'g') printf("go go go\n"); else if (ch == 'y') printf("wait a minute\n"); else printf("something must be wrong...\n"); } while (getchar() != EOF); return 0; }
Task4
#include<stdio.h> #include<math.h> int main() { int x ; int n, a; double s=0,u=0; do { scanf_s("%d%d", &n, &a); for (x=1; x <= n; x++) { u += a * pow(10, (x - 1)); s += x / u; } printf("n=%d,a=%d,s=%lf\n", n, a, s); s = 0; u = 0; } while (getchar() != EOF); return 0; }
Task5
#include<stdio.h> int main() { int x, y; for (x = 1; x <= 9; x++) { for (y = 1; y <= x; y++) { printf("%d*%d=%-3d", x, y, x * y); } printf("\n"); } return 0; }
Task6
#include<stdio.h> int main() { int n; printf("imput:"); scanf_s("%d", &n); int total = 2 * n - 1; for (int i = 0; i < n; i++) { for (int t = 1; t <= total; t++) { if (t > i && t < 2 * n - i) printf(" o\t"); else printf("\t"); if (t == total) printf("\n"); } for (int t = 1; t <= total; t++) { if (t > i && t < 2 * n - i) printf("<H>\t"); else printf("\t"); if (t == total) printf("\n"); } for (int t = 1; t <= total; t++) { if (t > i && t < 2 * n - i) printf("I I\t"); else printf("\t"); if (t == total) printf("\n"); } printf("\n"); } return 0; }
当输入为n时:
第i行,需要打印 (2n-2i+1)个小人
第i行,前面需要打印(i-1)个空白