task1
#include<stdio.h> #include<stdlib.h> #include<time.h> #define N 5 #define N1 374 #define N2 465 int main() { int number; int i; srand( time(0) ); for (i = 0;i < N;++i) { number = rand() % (N2 - N1 + 1) + N1; printf("202383290376%04d\n", number); } return 0; }
task2
#include <stdio.h> int main() { char colour; while (scanf("%c", &colour) != EOF) { if (colour >= 'a' && colour <= 'z') { if (colour == 'r') { printf("stop!\n"); } else if (colour == 'y') { printf("wait a minute\n"); } else if (colour == 'g') { printf("go go go\n"); } else { printf("something must be wrong...\n"); } } } return 0; }
task3
#include<stdio.h> #include<stdlib.h> #include<time.h> #define N 1 #define N1 1 #define N2 30 int main() { int number; int t, i, n; srand(time(0)); for (i = 0;i < N;++i) { number = rand() % (N2 - N1 + 1) + N1; } printf("先偷偷把答案告诉你:%d\n", number); printf("猜猜2023年11月那天会是你的lucky day\n"); printf("那么现在开始喽,你有三次机会,猜吧:"); for (t = 1;t <= 3;t++) { scanf("%d", &n); if (n < number) { printf("你猜的日期早啦,还没到呢\n"); } else if (n > number) { printf("你猜的日期晚啦,已经过了\n"); } else { printf("恭喜你猜对啦\n");break; return n; } } printf("次数用完辣,偷偷告诉你,你的lucky day是:%d",number); return 0; }
task4
#include<stdio.h> #include<math.h> int main() { int n, a; while (scanf("%d%d", &n, &a) != EOF) { double s = 0; double t = 0; for (int i = 1; i <= n; ++i) { t = t + pow(10, i - 1) * a; s = s + i / t; } printf("n=%d,a=%d,s=%f", n, a, s); } }
task5
#include <stdio.h> int main(){ int i,j; for(i=1;i<=9;i++){ for(j=1;j<=i;j++) printf("%d*%d=%2d ",i,j,i*j); printf("\n"); } return 0; }
task6
#include<stdio.h> int main() { int n,i,j,m,x; scanf("%d",&n); for(i=n;i>=0;i--) { m=2*i+1; for(x=i;x<n;x++) printf("\t"); for(j=1;j<=m;j++) { printf(" O \t"); } printf("\n"); for(x=i;x<n;x++) printf("\t"); for(j=1;j<=m;j++) { printf("<H>\t"); } printf("\n"); for(x=i;x<n;x++) printf("\t"); for(j=1;j<=m;j++) { printf("I I\t"); } printf("\n"); } return 0; }