task2
#include <stdio.h> #include <stdlib.h> #include <time.h> #define N 5 #define R1 586 #define R2 701 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; }
取一个R1,R2之间的随机数
生成随机学号
#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); getchar(); 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; }
#include <stdio.h> #include <math.h> int main() { double C,F; while(scanf("%lf", &C) != EOF) { F = 9 * C / 5 + 32; printf("摄氏度C=%.2lf时,华氏度F=%.2lf\n", C,F); printf("\n"); } return 0; }
#include <stdio.h> #include <math.h> int main() { char a; while(scanf("%c", &a) != EOF) { getchar(); switch (a) { case 'r': printf("stop!\n"); break; case 'g': printf("go go go\n"); break; case 'y': printf("wait a minute\n"); break; default: printf("some thing must be wrong...\n"); break; } } return 0; }
#include <stdio.h> #include <math.h> #include<stdlib.h> #include<time.h> int main() { int a, d,t; t = 0; srand(time(0)); a = rand() % 30 + 1; printf("猜猜2023年4月那一天会是你的lucky day\n"); printf("开始了,你有三次机会,猜吧(1-30):"); scanf("%d", &d); for(;a!=d&&t<3;) { if (a > d) printf("猜早了\n"); else printf("猜晚了\n"); t = t + 1; if (t < 3) scanf("%d", &d); } if (t == 3) printf("次数用完了,你的lucky day是%d号", a); else printf("哇,猜中了"); return 0; }
#include <stdio.h> #include <math.h> #include<stdlib.h> #include<time.h> int main() { int a, b, c; a = 1; b = 1; for (; a<=9;b=1) { for (; b <= a;) { c = a * b; printf("%dx%d=%d ", b, a, c); b = b + 1; } printf("\n"); a = a + 1; } return 0; }
#include <stdio.h> #include <math.h> #include<stdlib.h> #include<time.h> int main() { int t, a,i; for (a = 6; a >= 1;) { for (i = 1; i <= 6 - a;) { printf("\t"); i = i + 1; } for (t = 1; t <= 2 * a - 1;) { printf(" o \t"); t = t + 1; } printf("\n"); for (i = 1; i <= 6 - a;) { printf("\t"); i = i + 1; } for (t = 1; t <= 2 * a - 1;) { printf("<H>\t"); t = t + 1; } printf("\n"); for (i = 1; i <= 6 - a;) { printf("\t"); i = i + 1; } for (t = 1; t <= 2 * a - 1;) { printf("I I\t"); t = t + 1; } printf("\n"); a = a - 1; } return 0; }