实验2
问题1:确保输出的数值在374-465之间
问题2:输出4个“学号+0+三位随机数”形式的随机数值
#define _CRT_SECURE_NO_WARNINGS #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("202383290452%04d\n", number); } return 0; }
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> int main() { char t = ' '; while (scanf("%c", &t) != EOF) { switch (t) { case'r':printf("stop!\n"); break; case'g':printf("go go go\n"); break; case'y':printf("wait a minute\n"); break; default:printf("something must be wrong...\n"); break; } getchar(); } }
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> #include<time.h> int main() { int answer = 0; int number = 0; int i = 0; srand(time(0)); number = rand()%(30 - 1 + 1) + 1; printf("guess your lucky day\n" "开始喽,你有三次机会,猜吧(1~30):" ); for (i = 1; i <= 3; i++) {scanf("%d", &answer); if ((answer - number) > 0) printf("late\n"); else if ((answer - number) == 0) { printf("correct\n"); exit(0); } else printf("early\n"); } printf("your lucky day is:%d", number); }
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> int main() { int up = 1; int down = 0; int n = 1; int i = 1; double s = 0; int a = 1; while (scanf("%d%d", &n,&a) != EOF) { for (i = 1; i <= n; i++) { up = i; down = (down * 10 + 1) * a; s = (double)s +(double) up / down; } printf("n=%d a=%d s=%lf", n, a, s); } }
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> int main() { int line = 1; int column = 1; int value = 1; for (column = 1; column <= 9; column++) { for (line = 1; line <= column; line++) { value = line * column; printf("%d×%d=%d\t", column, line, value); } printf("\n"); } }
#define _CRT_SECURE_NO_WARNINGS #include<stdlib.h> #include<stdio.h> void people(char a, char b, char c, int all, int n) { int j; for (j = 0; j < n; j++) printf(" \t"); int h; for (h = 2 * (all - n) - 1; h > 0; h--) printf("%c%c%c\t", a, b, c); printf("\n");} int main() { int i=0, j=0, n=1; printf("input n:"); scanf("%d", &n); for (i = 0; i < n; i++) { people(' ', 'o', ' ', n, i); people('<', 'H', '>', n, i); people('I', ' ', 'I', n, i); } return 0; }