首页 > 其他分享 >实验2

实验2

时间:2023-03-22 23:22:55浏览次数:33  
标签:include return int scanf 实验 printf main

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

 

 

实验任务2

 

#include<stdio.h>
int main()
{
    int a1,a2,a3;
    char c1,c2,c3;
    double x,y;
    
    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=%f,y=%lf\n",x,y);
    
    return 0;
    
}

 

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

 

 

 

 

 

 实验任务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 C,F;
    
    while (scanf("%lf",&C)!=EOF)
    {
        F=C*9/5+32;
        printf("摄氏度c=9.00时,华氏度f=%lf\n",F);
        printf("\n"); 
    }
    return 0;
}

 

 实验任务4

#include<stdio.h>
#include<math.h>
int main()
{
    char a;
    while(scanf("%c",&a)!=EOF)
    {
        
        if(a=='G'||a=='g')
           
           printf("go go go\n");
           
        else if(a=='y'||a=='Y')
            
            printf("wait a minute\n");
           
        else if(a=='r'||a=='R')
          
           
           printf("stop!\n");
        else if(a!='y'&&a!='Y'&&a!='g'&&a!='G'&&a!='r'&&a!='R')
          printf("something must be wrong\n");}
        
          
     return 0;
}

 

 实验任务5

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

 

 实验任务6

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

 

 实验任务7

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

 

 

 

标签:include,return,int,scanf,实验,printf,main
From: https://www.cnblogs.com/zy250106/p/17223357.html

相关文章

  • 实验2
    task1(1)line18代码实现的功能是:一个586到781间的随机数(2)该程序的功能为随机生成586到781之间的"真·随机数"task2//.2.2.c.cpp:定义控制台应用程序的入......
  • 实验2
    task1编程代码#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;s......
  • 实验二
    实验任务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;srand(time......
  • 实验2 字符串和列表
    一、实验结论:1、实验任务1:task1.py程序源码:1#字符串的基础操作2#课堂上没有演示的一些方法34x='nbaFIFA'5print(x.upper())#字符串转......
  • 实验2 字符串和列表
    任务1x='nbaFIFA'print(x.upper())print(x.lower())print(x.swapcase())print()x='abc'print(x.center(10,'*'))print(x.ljust(10,'*'))print(x.rjust(10,'*'......
  • 实验2
    2.1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN6#defineR1586#defineR2701intmain(){intnumber;inti;srand(time(0));for(i=0;......
  • 实验2
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;srand(ti......
  • 实验2
    实验任务1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;......
  • 实验2 字符串与列表
    1x='nbaFIFA'2print(x.upper())3print(x.lower())4print(x.swapcase())5print()67x='abc'8print(x.center(10,'*'))9print(x.ljust(10,'*'))......