实验任务1
#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("202283300%04d\n",number); } system("pause"); return 0; }
Q1:获得一个R1到R2的随机数
Q2:生成一串与时间有关的随机数
实验任务2
#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); getchar(); 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; }
实验任务3
#include <stdio.h> #include <math.h> #include <stdlib.h> int main() { double x,ans; scanf("%lf",&x); ans=pow(x,365); printf("%.2f的365次方:%.2f\n",x,ans); system("pause"); return 0; }
实验任务3-2
#include <stdio.h> #include <math.h> #include <stdlib.h> int main() { double x,ans; while(scanf("%lf",&x)!=EOF){ ans=pow(x,365); printf("%.2f的365次方:%.2f\n",x,ans); printf("\n"); } system("pause"); return 0; }
实验任务3-3
#include <stdio.h> #include <stdlib.h> #include <math.h> int main() { int c; double f,x; while (scanf_s("%d", &c)) { f = 9.0 / 5 * c + 32; x = c; printf("摄氏度c=%.2lf时,华氏度f=%.2lf", x, f); printf("\n"); } system("pause"); return 0; }
实验任务4
#include <stdio.h> #include <stdlib.h> int main() { char x; while(x = getchar()) { getchar(); if (x == 'r') printf("stop!\n"); else if (x == 'g') printf("go go go\n"); else if (x == 'y') printf("wait a minute\n"); else printf("some thing must be wrong\n"); } return 0; }
实验任务5
#include <stdio.h> #include <stdlib.h> #include <time.h> int main() { int m,n,i; srand(time(NULL)); i = 1; n = rand() % 30+1; m = 0; printf("猜猜2023年4月哪一天会是你的lucky day\n开始喽,你有三次机会,猜吧(1~30):"); for (; i <= 3; i++) { scanf_s("%d", &m); if (m == n) { printf("哇,猜中了:)\n"); break; } else if (m < n) printf("你猜的日期早了,你的lucky day还没到呢\n"); if (m > n) printf("你猜的日期晚了,你的lucky day已经过啦\n"); } printf("次数用完啦,偷偷告诉你:4月,你的lucky day是%d号", n); return 0; }
实验任务6
#include <stdio.h> int main() { int column,line,value; column = 1; line = 1; value = column * line; for(column=1;column<=9;column++) { for (line=1; column >= line;line++) { value = column * line; printf("%d*%d=%d ", column, line, value); } printf("\n"); } return 0; }
实验任务7
#include <stdio.h> int main() { int n; printf("input n:"); scanf_s("%d", &n); for (int i = 1; i <= n; i++) { for (int k = 1; k <= 3; k++) { for (int j = 1; j <= i - 1; j++) { printf(" "); } for (int j = 1; j <= 2 * (n - i) + 1; j++) { if(k==1) printf(" O "); if(k==2) printf("<H> "); if(k==3) printf("I I "); } printf("\n"); } } return 0; }
标签:include,return,int,实验,printf,line,main From: https://www.cnblogs.com/qybceehs/p/17234017.html