首页 > 其他分享 >实验二

实验二

时间:2023-03-18 16:35:24浏览次数:26  
标签:lf include int scanf 实验 printf main

task1.c

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

 

 

问题1.生成一个随机数

问题2.在202283300586到202283300701中随机取5个数

 

task2.c

#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_1.c

#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_2.c

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

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

 

 

task4.c

#include <stdio.h>
int main()
{
    char m;
    while(scanf("%c",&m) !=EOF)
    {
        switch(m)
        {
    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;
}

 

 

task5.c

#include <stdio.h>
#include <time.h>
int main()
{
    int i, x, flag, y;
    flag = 1;

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

 

 

 

 

task6.c

 

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

}

 

 

 

task7.c

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

 

 

2*(n-i)+1个小人

i-1个\t

总结:语法应用还不熟练,好多都不太会。

标签:lf,include,int,scanf,实验,printf,main
From: https://www.cnblogs.com/zzx202283300616/p/17231048.html

相关文章

  • 实验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函数要使用一个外设首先要对它进行初始化,所以先看串口的初始化函数,其声明......
  • 实验2
    实验任务1实验代码#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti......
  • 实验2
    实验任务1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;......
  • 实验2
    实验任务一运行结果  程序源码#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumbe......
  • 实验二
    1、程序源码#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){ intnumber; inti; srand(time(0)......
  • 实验2
     任务一#include<stdio.h>#include<math.h>#include<stdlib.h>intmain(){ doublex,ans; while(scanf("%if",&x)!=EOF) { printf("202283300......
  • 实验2 c语言输入输出和控制语句应用编程
    TEST 1源代码:#include<stdlib.h>#include<stdio.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){  intnumber;  inti;  sran......
  • 实验2
    #include<stdio.h>//task2.1#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;s......