首页 > 其他分享 >实验2

实验2

时间:2023-03-19 15:33:07浏览次数:38  
标签:程序运行 int scanf 源码 实验 printf include

实验任务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);
    }

    system("pause");

    return 0;
}

 

程序运行截图

 

讨论:line  18是随机生成586—701之间的一个随机数

          程序功能是随机生成五个学号

实验任务2

程序源码

#include<stdio.h>
#include<stdlib.h>
#include<math.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;
}

 

程序运行截图

 

讨论:

实验任务3

程序源码

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

}

 

程序运行截图

程序源码

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

int main()
{
    double c, f;

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

    system("pause");

    return 0;

}

 

程序运行截图

 

                     

                     

 

讨论:

实验任务4

程序源码

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

int main()
{
    char color;
    while(scanf("%c", &color) != EOF)
    {
        getchar();
        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;
        }
    }
    system("pause");

    return 0;

}

 

程序运行截图

 

讨论:

实验任务5

程序源码

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

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

    return 0;

}

 

程序运行截图

                      

 

                     

 

讨论:

实验任务6

程序源码

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

int main()
{
    int i, n, s;
    for(n = 1; n <= 9; n++){
        for(i = 1; i <= n; i++){
            s = n * i;
            printf(" %dx%d = %2d ", n, i, s);
        }
        printf("\n");
    }
    system("pause");

    return 0;

}

 

程序运行截图

 

讨论:

实验任务7

程序源码

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

 

程序运行截图

 

讨论:

标签:程序运行,int,scanf,源码,实验,printf,include
From: https://www.cnblogs.com/djwzxy/p/17223584.html

相关文章

  • 实验报告1
     ......
  • 实验二
    test1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;sran......
  • 实验二
    实验任务一  1:随机生成一个586和701之间的数字 2:随机生成五个最后四位在586和701之间的数字 实验任务二#include<stdio.h>intmain(){doublex,y;......
  • 实验2
    实验任务1源代码#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;......
  • pta python实验1-3
    7-1HelloWorld这是学习每种程序设计语言的第一个实例。‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬输出Hell......
  • 实验2
    task1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;srand......
  • 实验2
    实验任务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;......
  • SYNU PTA C++ 第三章实验题
    题目详细内容见PTA,仅提供答案参考。7-7冒泡1#include<iostream>2usingnamespacestd;34voidmerge(int*arr,intleft,intmid,intright)5{6......
  • 实验二
    task1.c#defineR1586#defineR2701intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){number......