首页 > 其他分享 >实验二

实验二

时间:2023-03-22 23:35:34浏览次数:34  
标签:include int scanf lucky 实验 printf main

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("202283300%04d\n",number);
    }
    return 0;
}

问题1:随机生成586-701之间的整数

问题2:随机生成202283300586-202283300701之间的学号

 

task2

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

 

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

task3_3

#include <stdio.h>
#include <math.h>

int main()
{
    double x, ans;
    
    while(scanf("%lf", &x) != EOF)
    {
        ans = x*9/5 + 32;
        printf("摄氏度c = %.2f时,华氏度f = %2f\n", x, ans);
        printf("\n");
    }
    
    return 0;
}

 

task4

#include <stdio.h>

int main()
{
    char inp;
    int flag;
    
    flag = 0;
    while(scanf("%c", &inp) != EOF)
    {
        getchar();
        if (inp == 'y') 
        {
            printf("wait a minute\n");
            flag = 1;
        }
        else if (inp == 'g') 
        {
            printf("go go go\n");
            flag = 1;
        }
        else if (inp == 'r') 
        {
            printf("stop!\n");
            flag = 1;
        }
        else if (inp!= 'y'&&inp!= 'g'&&inp!= 'r') 
        {
            printf("something must be wrong...\n");
        }
    }
    
    return 0;
}

 

task5

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

int main() 
{
    
    srand(time(0));
    
    int d = rand() % 30 + 1;
    
    printf("猜猜2023年4月哪一天会是你的lucky day\n\n");
    printf("开始喽,你有三次机会,猜吧(1~30):");
    
    int x;
    scanf("%d", &x);
    printf("\n");
    
    if(x == d) 
    {
        printf("哇,猜中了:~)");
    } 
    else {
        if(x < d) { printf("你的日期猜早了,你的lucky day还没到呢\n\n"); }
        if(x > d) { printf("你的日期猜晚了,你的lucky day已经过了\n\n"); }
        printf("再猜(1~30):");
        scanf("%d", &x);
        printf("\n");
        
        if(x == d) 
        {
            printf("哇,猜中了:~)");
        } 
        else 
        {
            if(x < d) { printf("你的日期猜早了,你的lucky day还没到呢\n\n"); }
            if(x > d) { printf("你的日期猜晚了,你的lucky day已经过了\n\n"); }
            printf("再猜(1~30):");
            scanf("%d", &x);
            printf("\n");
        
            if(x == d) 
            {
                printf("哇,猜中了:~)");
            } 
            else 
            {
                if(x < d) { printf("你的日期猜早了,你的lucky day还没到呢\n\n"); }
                if(x > d) { printf("你的日期猜晚了,你的lucky day已经过了\n\n"); }
                printf("次数用完了,偷偷告诉你:4月,你的lucky day是%d号", d);
            }
        }
    }
    
    system("pause");
    return 0;
}

 

task6

#include <stdio.h>

int main() 
{
    
    int i,j=1;
    
    while(i<=9) 
    {
        j=1;
        while(j<=i) 
        {
            printf("%d×%d=%d\t",j,i,i*j);
            j++;
        }
        printf("\n");
        i++;
    }
    
    return 0;
}

 

task7

#include<stdio.h>
#include<stdlib.h>
int main() 
{
    
    int n;
    
    printf("input n:");
    scanf("%d", &n);
    
    for(int i = 1;i <= n; i++) 
    {
        for(int k = 1;k <= 3; k++) 
        {
            for(int j = 1;j <= i - 1; j++) 
            {
                printf("      ");
            }
            for(int j = 1;j <= 2 * (n - i) + 1; j++) 
            {
                if(k == 1) printf(" O    ");
                if(k == 2) printf("<H>   ");
                if(k == 3) printf("I I   ");
            }
            printf("\n");
        }
    }
    system("pause");
    return 0;
}

 

标签:include,int,scanf,lucky,实验,printf,main
From: https://www.cnblogs.com/zhuquekameitielongyu/p/17245884.html

相关文章

  • 实验2
    实验任务1程序源码#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;int......
  • 实验2 字符串和列表
    task1x='nbaFIFA'print(x.upper())print(x.lower())print(x.swapcase())print()x='abc'print(x.center(10,'*'))print(x.ljust(10,'*'))print(x.rjust(10,'*'))......
  • 实验2
    实验任务1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;sr......
  • 实验2
    task1(1)line18代码实现的功能是:一个586到781间的随机数(2)该程序的功能为随机生成586到781之间的"真·随机数"task2//.2.2.c.cpp:定义控制台应用程序的入......
  • 实验2
    task1编程代码#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;s......
  • 实验二
    实验任务1源码#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;......
  • 实验二
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;srand(time......
  • 实验2 字符串和列表
    一、实验结论:1、实验任务1:task1.py程序源码:1#字符串的基础操作2#课堂上没有演示的一些方法34x='nbaFIFA'5print(x.upper())#字符串转......
  • 实验2 字符串和列表
    任务1x='nbaFIFA'print(x.upper())print(x.lower())print(x.swapcase())print()x='abc'print(x.center(10,'*'))print(x.ljust(10,'*'))print(x.rjust(10,'*'......