2.1
#include <stdio.h> #include <stdlib.h> #include <time.h> #define N 6 #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; }
2.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); 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; }
2.3
#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; }
2.4
#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",C, F); printf("\n"); printf("\n"); } return 0; }
2.5
#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; }
2.6
#include <stdio.h> #include <math.h> #include <time.h> #include <stdlib.h> int main() { int num, i, n; srand(time(0)); num = rand() % (30 - 1 + 1) + 1; printf("猜猜2023年4月哪一天是你的lucky day\n"); printf("\n"); printf("开始喽,你有三次机会,猜吧(1~30):"); scanf("%d", &n); printf("\n"); for(i=1;i<3;i++) { if (n > num) printf("你猜的日期晚了,你的lucky day已经过了\n"); else if (n < num) printf("你猜的日期早了,你的lucky day还没到呢\n"); else { printf("哇,猜中了:-)"); break; } printf("\n"); printf("再猜(1~30):"); scanf("%d", &n); printf("\n"); } if (n != num) printf("次数用完啦。偷偷告诉你:4月,你的lucky day是%d号",num); return 0; }
2.7
#include<stdio.h> int main() { int line, column; for(line=1;line<10;line++) { for(column=1;column<line+1;column++) printf("%d*%d=%d ",column,line,line*column); printf("\n"); } return 0; }
2.8
#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; }
标签:include,int,scanf,num,实验,printf,main From: https://www.cnblogs.com/ry202283300666/p/17245325.html