实验二
实验一
代码:
#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); } system("pause"); return 0; }
结果:
第18行的作用是,生成一个R2-R1+1到R2+1之间的随机数
这个程序的功能是输出以20228330开头的12位随机数
实验2
#include<stdio.h> #include <stdlib.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); system("pause"); return 0; }
实验3
#include <stdio.h> #include <math.h> #include <stdlib.h> int main() { double x, ans; scanf("%lf", &x); ans=(9/5)*x+32; printf("摄氏度等于%.2f时,华氏度F=%.2f\n", x, ans); system("pause"); return 0; }
实验5
#include<stdio.h> #include <stdlib.h> #include<math.h> #include <time.h> int main() { int n,a; n=rand()%30+1; srand(time(0)); printf("猜猜2023年4月哪一天是你的幸运日)\n"); scanf("%d",&a); if(a==n) printf("猜对啦"); else if(a>n) printf("猜的日期晚啦,你的幸运日已经过了\n"); else printf("猜的日期早啦,你的幸运日还没到呢\n"); scanf("%d",&a); if(a==n) printf("猜对啦"); else if(a>n) printf("猜的日期晚啦,你的幸运日已经过了\n"); else printf("猜的日期早啦,你的幸运日还没到呢\n"); scanf("%d",&a); if(a==n) printf("猜对啦"); else printf("不能再猜啦,悄悄告诉你,你的幸运日是%d",n); system("pause"); return 0; }
实验6
#include<stdio.h> #include <stdlib.h> int main() { printf("1*1= 1\n"); printf("1*2= 2 2*2= 4\n"); printf("1*3= 3 2*3= 6 3*3= 9\n"); printf("1*4= 4 2*4= 8 3*4=12 4*4=16\n"); printf("1*5= 5 2*5=10 3*5=15 4*5=20 5*5=25\n"); printf("1*6= 6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36\n"); printf("1*7= 7 2*7=14 3*7=21 4*7=28 5*7=35 6*7=42 7*7=49\n"); printf("1*8= 8 2*8=16 3*8=24 4*8=32 5*8=40 6*8=48 7*8=56 8*8=64\n"); printf("1*9= 9 2*9=18 3*9=27 4*9=36 5*9=45 6*9=54 7*9=63 8*9=72 9*9=81\n"); system("pause"); return 0; }
实验7
#include<stdio.h> #include <stdlib.h> int main() { int i,j; int n,m,l; m=2*n-1; l=n; printf("input:"); scanf("%d",&n); for(i=1;i<=n;n--) { m=2*n-1; for(j=1;j<=m;j++) { printf(" 0\t"); } printf("\n"); for(j=1;j<=m;j++) { printf("<H>\t"); } printf("\n"); for(j=1;j<=m;j++) { printf("I I\t"); } printf("\n"); } system("pause"); return 0; }
第1行有2*4-1个小人
第i行有(n-i)*2-1个小人