实验2

task1

代码:

#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;
}

 

运行结果:

  

 

 

task 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;
}

运行结果:   

或者

#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);
    
    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;
}                                            

 

                            

 

 task3

 

#include <stdio.h>
#include <stdlib.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");
    }
    system("pause");
    return 0;
}

运行结果:

 

 task3-3

代码;

#include <stdio.h>
#include <stdlib.h>
int main()
{
double c,f;

printf("enter the centigrade:");
while((scanf("%lf",&c))!=EOF)
{
f = 9.0/5*c + 32;
printf("the Fahrenhert is: %.2lf\n",f);
}
system("pause");
return 0;
}

运行结果:    

 

 

 

 

task4

代码:

int main()
{
char c;


while((c=getchar())!=EOF)
{
switch(c)
{
case'r':printf("stop!");break;
case'g':printf("go go go!");break;
case'y':printf("wait a minute");break;
default:printf("something must be wrong...");
}
printf("\n");
c = getchar();         //字符变量,如果不加getchar(),就会把回车当字符,多出一行something must be wrong;
}
system("pause");
return 0;
}

运行结果:

 

 

task5

代码:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main()
{
int day,n,i;
i = 1;
day = rand()%30+1;
printf("猜猜2023年4月哪一天会是你的lucky day");
printf("开始喽,你有三次机会,猜吧(1~30)");
while(i<4){
scanf("%d",&n);
if(n<day){
i++;
printf("你猜的日期早了,你的lucky day还没到呢");}

else if(n>day){
i++;
printf("你猜的日期晚了,你的lucky day已经过啦");}
else if(n==day){
printf("哇,猜中了:-");}
}
printf("你的lucky day是%d",day);

system("pause");
return 0;
}

运行结果:

 

 

 

 

task6

代码:

#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,j;
for(i=1;i<=9;i++){

for(j=1;j<=i;j++)
printf("%d*%d = %d ",i,j,i*j);
printf("\n");
}
system("pause");
return 0;
}

运行结果:

 

 

task7

代码:

#include <stdio.h>
#include <stdlib.h>
int main()
{
int n,i,t,m,s,l;
m=1;
printf("input the number of line you want:\n");
scanf("%d",&n);

for(i=1;i<=n;i++){
for(m=1;m<=i-1;m++){
printf("\t");}
for(t=1;t<=2*n-2*i+1;t++)

printf(" o \t");
printf("\n");
for(m=1;m<=i-1;m++)
printf("\t");
for(s=1;s<=2*n-2*i+1;s++)
printf("<H>\t");
printf("\n");
for(m=1;m<=i-1;m++)
printf("\t");
for(l=1;l<=2*n-2*i+1;l++)
printf("I I\t");
printf("\n");

}

system("pause");
return 0;
}
运行结果:

 

 

 

 

 

posted @ 2023-03-18 00:19  岁杪听风  阅读(47)  评论(0)    收藏  举报