#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; }
问题一:生成586-701之间的随机数
问题二:一次性随机生成五个202283300。。。后面三个数字为586-701之间的随机数
#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); getchar(); scanf("%lf,%lf\n",x,y); printf("x=%lf,y=%lf\n",x,y); system("pause"); return 0; }
数字和数字之间需要空格,字母和小数不需要
#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; }
#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",c,F); printf("\n"); } return 0;
#include <stdio.h> int main() { char c; while(scanf("%c", &c) != EOF) { switch(c){ case'y':printf("wait a minute\n");break; case'g':printf("go go go");break; case'r':printf("stop!");break; case'x':printf("something must be wrong");} }getchar(); return 0; }
#include <stdio.h> #include <stdlib.h> #include <time.h> int main() { int x,n,i; srand(time(0)); x = rand() %(30)+1; printf("猜猜2023年4月哪一天会是你的lucky day\n开始喽,你有三次机会,"); for(i=0;i<3;i++){ printf("猜吧(1-30):"); scanf("%d",&n); if(n==x) {printf("哇,你中了!!!\n");break;} else if(n<x) printf("你猜的时间早了哦\n"); else printf("你猜的时间晚了哦\n"); if(i==2) printf("次数用完啦,偷偷告诉你,4月你的lucky day是%d号\n",x); } system("pause"); return 0; }
#include<stdio.h> #include<stdlib.h> #include<math.h> #include<time.h> int main() { int i, j; for(i = 1;i <= 9; i++) { for(j = 1;j <= i; j++) { printf("%d*%d =%3d ", j, i, j * i); } printf("\n"); } system("pause"); return 0; }
#include<stdio.h> int main() { int n,i,j,k; printf("input n:", n); scanf("%d", &n); for(i=n;i>=1;i--){ for(k=i;k<n;k++){ printf("\t"); } for(j=1;j<=i*2-1;j++){ printf(" o \t"); } printf("\n"); for(k=i;k<n;k++){ printf("\t");} for(j=1;j<=i*2-1;j++){ printf("<H>\t"); } printf("\n"); for(k=i;k<n;k++){ printf("\t");} for(j=1;j<=i*2-1;j++){ printf("I I\t"); } printf("\n"); } return 0; }
标签:lf,include,int,scanf,实验,printf,main From: https://www.cnblogs.com/cybcyb/p/17223566.html