实验2
test 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("20228330%04d\n",number);
}
return 0;
}
实验截图
实验结论
在586和701间任意输出一个数
test 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 = %lf, y = %lf\n",x, y);
return 0;
}
test 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;
}
实验图片
实验4
}
else{
if(x<number)
{
printf("早了\n再猜\n");}
if(x>number)
{
printf("晚了\n再猜\n");}}
i++;
}
while(i==3)
{scanf("%d",&x);
if(x==number){
printf("对了\n");
break;}
else{
if(x<number)
{
printf("早了\n");
printf("偷偷告诉你:正确日期是:%d",number);}
if(x>number)
{
printf("晚了\n");
printf("偷偷告诉你:正确日期是:%d",number);}
break;
}
return 0;}}
}
else{
if(x<number)
{
printf("早了\n再猜\n");}
if(x>number)
{
printf("晚了\n再猜\n");}}
i++;
}
while(i==3)
{scanf("%d",&x);
if(x==number){
printf("对了\n");
break;}
else{
if(x<number)
{
printf("早了\n");
printf("偷偷告诉你:正确日期是:%d",number);}
if(x>number)
{
printf("晚了\n");
printf("偷偷告诉你:正确日期是:%d",number);}
break;
}
return 0;}}
Test 5
#include<stdio.h>
int main()
{
char light ;
while(scanf("%c",&light)!=EOF)
{
getchar();
switch (light)
{
case 'y':printf("wait a minute\n");
break;
case 'g':printf("go go go\n");
break;
case 'r':printf("stop!\n");
break;
default:printf("something must be wrong...\n");
break;
}
}
return 0;
}
test 6
源代码
#include <stdio.h>
#include <math.h>
int main(){
int i,j,v;
for(i=1;i<=9;i++){
for(j=1;j<=i;j++){
v=i*j;
printf("%dx%d=%d",i,j,v);
printf("\t");
}
printf("\n");
}
return 0;
}
实验图片
test 7
源代码
#include<stdio.h>
int main()
{
int n,i,j;
printf("input n:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i-1;j++ ){
printf("\t");}
for(j=1;j<=2*(n-i)+1;j++){
printf(" o \t");}
printf("\n");
for(j=1;j<=i-1;j++ ){
printf("\t");}
for(j=1;j<=2*(n-i)+1;j++){
printf("<H>\t");}
printf("\n");
for(j=1;j<=i-1;j++ ){
printf("\t");}
for(j=1;j<=2*(n-i)+1;j++){
printf("I I\t");}
printf("\n");
printf("\n\n");
}
return 0;}
运行