首页 > 其他分享 >实验二

实验二

时间:2023-03-19 14:34:17浏览次数:31  
标签:include int scanf 实验 printf test main

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

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

 

标签:include,int,scanf,实验,printf,test,main
From: https://www.cnblogs.com/Dream37024514/p/17223577.html

相关文章

  • 实验二
    实验任务一  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......
  • 实验2 C语言输入输出和控制语句应用编程
    实验任务11#include<stdio.h>2#include<stdlib.h>3#include<time.h>4#defineN55#defineR15866#defineR27017intmain()8{9intn......
  • 202113020023李湘楠实验2实验报告
    //test1.c#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;sr......