首页 > 其他分享 >实验二

实验二

时间:2023-03-23 09:00:11浏览次数:27  
标签:include return int scanf 实验 printf main

#task1

#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中随机抽一个数赋值给number。

2、用于随机抽取5个学号。

 

#task2

#include<stdio.h>

int main()
{
 float x,y;
 char c1,c2,c3;
 int a1, a2, a3;

 scanf("%d,%d,%d",&a1,&a2,&a3);//a1,a2,a3前缺少&
 printf("a1=%d,a2=%d,a3=%d\n",a1 ,a2,a3);

 scanf("\n%c,%c,%c",&c1,&c2,&c3);
 printf("c1=%c, c2=%c, c3=%c\n",c1,c2,c3);

 scanf("\n%f,%f",&x,&y);
 printf("x=%f,y=%f\n",x,y);

 return 0;
}

 

#task3

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

 

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

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

 

#task4

#include<stdio.h>

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

 

#task5

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

int main()
{
    
       int n,i,k;
       
       srand((unsigned)time(NULL));
       n = rand() % 30 + 1;
       printf("猜猜2023年4月哪一天是你的lucky day吧");
       printf("\n开始咯,你有三次机会,猜吧(1~30):");
       scanf("%d",&i);
       for(k=1;i!=n&&k<=2;k++){
       if(i<n){
               printf("你猜小了\n");
           }
           else if(i>n){
               printf("你猜大了\n");
           }
           printf("再猜(1~30):");
           scanf("%d",&i);
           if(k==2&&i!=n){
           printf("\n");
           printf("次数用完了,偷偷告诉你,四月你的幸运日是%d\n",n);
           }
           }
           if(i==n){
           printf("哇,猜中了");}
         
           
       
       return 0;
}

 

#task6

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

 

#task7

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

当输入为n时:

第i行需要打印n-i+1个字符小人

第i行,前面需要使用i-1个\t

 

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

相关文章

  • 实验2
    任务1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;sr......
  • 实验二
    task1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;s......
  • 实验2
    实验任务1程序源码#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;int......
  • 实验2 字符串和列表
    task1x='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
    实验任务1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;sr......
  • 实验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......