首页 > 其他分享 >实验二

实验二

时间:2023-03-21 16:55:59浏览次数:22  
标签:程序运行 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);
    }
    return 0;
}

程序运行:

问题讨论:

1.在【586,701】这个区间内生成随机数

2.随机输出五名学生的学号

 

实验任务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);
    getchar();
    printf("c1 = %c, c2 = %c, c3 = %c\n", c1, c2, c3);
    
    scanf("%lf,%lf", &x, &y);                                   //double类型都要使用lf% 
    printf("x = %lf, y = %lf\n", x, y);
    
    
    
    return 0;
}

 

程序运行:

 

 

 

实验任务3

task3.1

程序源码:

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

int main()
{
   double x,ans;

   scanf("%lf",&x);
   ans=pow(x,365);
   printf("%.2f的365次方:%.2f\n",x,ans);

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

程序运行:

task.3.3

程序源码:

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

int main()
{
double c,f;

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

 

程序运行:

 

 

实验任务4

程序源码:

#include<stdio.h>

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

程序运行:

 

实验任务5

程序源码:

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

#define N 1
#define R1 1
#define R2 30

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

程序运行:

 

 

实验任务6

程序源码:

#include<stdio.h>

int main()
{
    int h,l;
    
    for(h=1;h<=9;h++)
    {
        for(l=1;l<=h;l++)
        {
            printf("%d*%d =%3d  ",h,l,h*l);
        }
        printf("\n");
    }
    return 0;
 } 

程序运行:

 

实验任务7

程序源码:

#include <stdio.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");
        }
    }
    
    
    return 0;
}

程序运行:

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

相关文章

  • 实验二
      实验任务1task1.c#include<stdio.h>#include<stdlib.h>#include<time.h>#defineR2701#defineN5#defineR1586intmain(){ intnumber; int......
  • 实验2
    实验一程序源码:#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;......
  • 跟着字节AB工具DataTester,5步开启一个实验
    更多技术交流、求职机会,欢迎关注字节跳动数据平台微信公众号,回复【1】进入官方交流群 火山引擎A/B测试平台DataTester孵化于字节跳动业务内部,在字节跳动,“万事皆A/B,一切可......
  • 跟着字节AB工具DataTester,5步开启一个实验
    更多技术交流、求职机会,欢迎关注字节跳动数据平台微信公众号,回复【1】进入官方交流群 火山引擎A/B测试平台DataTester孵化于字节跳动业务内部,在字节跳动,“万事皆A/B,......
  • 实验二
    试验任务一 程序源码#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;i......
  • 实验一 密码引擎-1-OpenEuler-OpenSSL编译
    实验一密码引擎-1-OpenEuler-OpenSSL编译0.安装Ubuntu和OpenEuler虚拟机1.下载最新的OpenSSL源码(1.1版本)2.用自己的8位学号建立一个文件夹,cd你的学号,用pwd获得绝......
  • 实验一 密码引擎-1-OpenEuler-OpenSSL编译
    0.安装Ubuntu和OpenEuler虚拟机安装openEuler-20.09安装登入openEuler系统1.下载最新的OpenSSL源码(1.1版本)Ubuntu22.04OpenSSL1.1.1tUbuntu最新版本下载参见......
  • 实验一 密码引擎-1-OpenEuler-OpenSSL编译
    任务详情0.安装Ubuntu和OpenEuler虚拟机下载最新的OpenSSL源码(1.1版本)用自己的8位学号建立一个文件夹,cd你的学号,用pwd获得绝对路径参考https://www.cnblogs.......
  • 实验一 密码引擎-1-OpenEuler-OpenSSL编译 _
    一、任务详情安装Ubuntu和OpenEuler虚拟机下载最新的OpenSSL源码(1.1版本)用自己的8位学号建立一个文件夹,cd你的学号,用pwd获得绝对路径参考https://www.cnblogs.com/......
  • 实验2
    一.任务1 #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;......