#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; }
1.line18的功能为在R1-R2之间生成随机数number
2.根据系统时间随机生成202283300586-202283300701之间的5个学号
实验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); 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 = %f, y = %lf\n",x, y); return 0; }
实验3
#include <stdio.h> #include <math.h> int main() { double x, ans; while(scanf("%lf", &x) != EOF) { ans = pow(x, 365); printf("%.2f的365次方: %.2f\n", x, ans); printf("\n"); } 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 = %.2f时,华氏度F = %.2f\n", C, F); printf("\n"); } return 0; }
实验4
#include <stdio.h> int main() { char x; while(scanf("%c", &x) != EOF) { switch(x){ case'y':printf("wait a minute\n");break; case'r':printf("stop!\n");break; case'g':printf("go go go\n");break; default:printf("something must be wrong...\n"); }getchar(); } return 0; }
实验5
#include <stdio.h> #include <stdlib.h> #include <time.h> int main() { int a,i,b; i=1; srand((unsigned)time(NULL)); a = rand()%(30-1+1)+1; printf("猜猜2023年4月哪一天会是你的lucky day\n\n开始喽,你有三次机会,猜吧(1~30):"); while(i<=3||b==a) { scanf("%d",&b); if(b==a) printf("哇,猜中了:-)\n\n"); else if(b>a) printf("你猜的日期晚了,你的lucky day已经过啦\n\n"); else if(b<a) printf("你猜的日期早了,你的lucky day还没到呢\n\n"); if(i<3&&a!=b) printf("再猜(1~30):"); i+=1; } if(i>3) printf("次数用完啦,偷偷告诉你:4月,你的lucky day是%d号\n\n",a); return 0; }
实验6
#include <stdio.h> int main() { int c,l,v; l=1; while(l<=9) { c=1; while(c<=l) { v=c*l; printf("%dx%d = %d",c,l,v); if(c==l) printf("\n\n"); else printf(" "); c+=1; } l+=1; } return 0; }
实验7
#include <stdio.h> int main() { int l,n,k,a,b,i,p; printf("input n
:"); scanf("%d",&l); i=1; while(l>=1) { a=l+l-1; b=l+l-2; n=k=p=1; while(n<=a) { while(p<i) { printf(" "); p++; } printf(" O "); if(k<=b) printf(" "); else printf("\n"); n++; k++; } n=k=p=1; while(n<=a) { while(p<i) { printf(" "); p++; } printf("<H>"); if(k<=b) printf(" "); else printf("\n"); n++; k++; } n=k=p=1; while(n<=a) { while(p<i) { printf(" "); p++; } printf("I I"); if(k<=b) printf(" "); else printf("\n\n"); n++; k++; } l--; i++; } return 0; }
标签:main,编程,int,scanf,输入输出,C语言,while,printf,include From: https://www.cnblogs.com/linbai7/p/17223532.html