实验二

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

问题一:生成一个R1~R2之间的整数

问题二:随机抽取学号,类似随机数字生成器

 

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);
    
    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 = %f, y = %lf\n",x, y);
    
    return 0;
}

 

test 3_1

#include <stdio.h>
#include <math.h>
int main()
{
    double x, ans;
    int i;
    for(i=1;i<=3;i++)
    {
    scanf("%lf", &x);
    ans = pow(x, 365);
    printf("%.2f的365次方: %.2f\n", x ,ans);
    }
    
    return 0; 
}

 

test 3_2

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

 

tesst 3_3

#include <stdio.h>
#include <math.h>
int main()
{
double c, f;
while(scanf("%lf", &c) != EOF)
{
f = 1.8*c+32;
printf("摄氏度c = %.2f时,华氏度f = %.2f\n", c, f);
printf("\n");
}
return 0;
}

 

test 4

#include<stdio.h>
int main()
{
    char color;
    while(scanf("%c", &color) != EOF)
    {
    switch(color)
    {
    case 'r':printf("stop!\n");break;
    case 'g':printf("go go go\n");break;
    case 'y':printf("wait a minute\n");break;
    default:printf("something must be wrong\n");break;
    }
    getchar();
    }
    return 0;
 } 

 

test 5

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
    int n, i, date, flag;
    srand(time(0)); 
    date = rand()%30+1;
    printf("猜猜2023年4月那一天会是你的lucky day\n");
    printf("开始喽,你有三次机会,猜吧(1~30): ");
    for(i = 1; i <= 3; i++)
    {
        scanf("%d",&n);
        if(n == date)
        {
            printf("猜中啦~");
            flag = 0;
            break;
        }
        else if(n < date && i != 3)
        {
            printf("猜早啦~\n再来一次吧:"); 
        }
        else if(n > date && i != 3)
        {
            printf("猜晚啦~\n再来一次吧:");
         } 
        else if(n < date && i == 3)
        {
            printf("猜早啦~\n");
        }
        else if(n > date && i == 3)
        {
            printf("猜晚啦~\n");
        }
    }
    if(flag)
    printf("次数用完啦,偷偷告诉你,你的lucky day是%d号哦~",date);
     
    return 0;
 } 

 

test 6

#include<stdio.h>
int main()
{
    int line = 1,  column = 1, product;
    for(;column <= 9; column++)
    {
        for(;line <= column; line++)
        {
            product = line * column;
            printf("%d×%d=%d \t",line,column,product);
        }
        printf("\n"); 
        line = 1;
    }
    return 0;
}

 

test 7

 当输入为n时:

第i行需要打印 2*(n+1-i)-1 个小人

第i行需要打印 i - 1 个空白

int main()
{
    int n, l, i, m, x;
    printf("输入一个n,生成n行倒金字塔形排列小人:");
    scanf("%d",&n);
    m = n;
    printf("\n");
    for(;n >= 1; n--)
    {
        for(x = m-n; x > 0; x--)
        {
            printf("   \t");
        }
        for(i = 1; i <= 2*n-1; i++)
        {
            printf(" o \t");
        }
        printf("\n");
        for(x = m-n; x > 0; x--)
        {
            printf("   \t");
        }
        for(i = 1; i <= 2*n-1; i++)
        {
            printf("<H>\t");
        }
        printf("\n");
        for(x = m-n; x > 0; x--)
        {
            printf("   \t");
        }
        for(i = 1; i <= 2*n-1; i++)
        {
            printf("I I\t");
        }
        printf("\n");
        printf("\n");
    }
    
    return 0;
}

 

posted @ 2023-03-19 14:23  睡猛龙  阅读(16)  评论(0)    收藏  举报