首页 > 其他分享 >实验二

实验二

时间:2023-03-19 13:44:56浏览次数:33  
标签:main int scanf printf 实验 ans include

实验任务一

 

 1:随机生成一个586和701之间的数字

 2: 随机生成五个最后四位在586和701之间的数字

 

实验任务二

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

 

 

实验任务三

3.1

  int main() 
  {
      double x, ans; 
    scanf("%lf", &x); 
    ans = pow(x, 365); 
    printf("%.2f的365次方: %.2f\n", x, ans);
    return 0;
      
  }

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

3.3

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

 

实验任务四

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

int main()
{
    char color;
    while(scanf("%c",&color)!=EOF)
    {
        getchar();
        switch(color){
            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...");break;
        }
        printf("\n");

    }
    system("pause");
    return 0;
}

 

 

实验任务5

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

int main()
{
    int number,data,i;
    srand((unsigned int)time(NULL));
    number=rand()%30+1;
    printf("猜猜今年4月哪天是你的幸运日\n");
    
    for(i=1;i<=3;i++){
        scanf("%d",&data);
        if(data==number){
            printf("猜中了\n");
            break;
        }
        if(data<number)
            printf("早了呢\n");
        if(data>number)
            printf("晚了呢\n");
        printf("你还有%d次机会\n",3-i);
    }
    if(data!=number)
       printf("偷偷告诉你,你的幸运日是%d号\n",number);
       
     return 0;
 }

 

 

实验任务6

#include<stdio.h>
int main()
{
    int i,j;
    for(i=1;i<=9;i++){
        for(j=1;j<=i;j++){
            printf("%dx%d=%2d",i,j,i*j);
            printf("\t");
        }
        putchar('\n');
    }
 }

 

实验任务7

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

 

标签:main,int,scanf,printf,实验,ans,include
From: https://www.cnblogs.com/xsh123456/p/17223548.html

相关文章

  • 实验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......
  • STM32 HAL库学习 (2) USART实验
    使用STM32F407串口:PA9、PA10(利用CH340G驱动)1.stm32f4xx_hal_uart.c函数说明HAL_UART_Init函数要使用一个外设首先要对它进行初始化,所以先看串口的初始化函数,其声明......