首页 > 其他分享 >实验2

实验2

时间:2023-03-22 22:47:37浏览次数:35  
标签:截图 include 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);
   }
    system("pause");
    return 0; 
}

 

运行截图

 

问题1  随机生成以0开头的4个数字

问题2  随机得到一个学号

 

task2

编程代码

#include<stdio.h>
#include<stdlib.h>
int main()
{
    double x,y;

    char c1,c2,c3;

    int a1,a2,a3;

    scanf("%d%d%d",&a1,&a2,&a3);

    scanf("%c%c%c",&c1,&c2,&c3);

    scanf("%lf%lf",&x,&y);

    printf("a1=%d,a2=%d,a3=%d\n",a1,a2,a3);

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

    printf("x=%lf,y=%lf\n",x,y);

    system("pause");

    return 0; 
}

运行截图

 

task3.2

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

    system("pause");

    return 0; 
}

 

 

运行截图

 

task3.3

编程代码

 

#include<stdio.h>
#include<stdlib.h>
int main()
{
    double F,C;
     while(scanf("%lf",&C)!=EOF)
    {
        F=C*9/5+32;
     printf("摄氏度=%.2f\n",C);
     printf("华氏度=%.2f\n",F);
    

    
    }

    system("pause");

    return 0; 
}

 

运行截图

 

 

编程代码

 

task4

#include<stdio.h>
#include<stdlib.h>
int main()
{char m;
while(scanf("%c",&m)!=EOF)
{
getchar();
switch(m)
{case'y':printf("wait a minute\n");
break;
case'g':printf("go go go\n");
    break;
case'r':printf("stop!\n");
    break;
default:printf("must be wrong\n");
    break;
}
   
    }

    system("pause");

    return 0; 
}

 

运行截图

 

 

task5

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
  int i=1;
  int number,x;
  srand(time(0));
  number=rand()%20+1;
  printf("猜猜2023年四月哪一天会是你的幸运日");
  printf("你有三次机会,猜吧(1~30)");
      while(i<4)
      {scanf("%d",&x);
      if(x>number)printf("猜晚了");
      else if(x<number)printf("猜早了");
          else if(x=number){printf("猜中了");break;}
           
        
          i++;}
      if(i>3)printf("次数用完了,你的幸运日是%d",number);
    system("pause");

    return 0; 
}

 运行截图

 

 

task6

#include<stdio.h>
#include<stdlib.h>
int main() {int n,m,i,k; i=1; k=1; while(i<=9) {while(k<=i) {m=i*k; printf("%dx%d=%2d ",k,i,m); k++;} printf("\n"); k=1; i++;} system("pause"); return 0; }

 

运行截图

 

 

task7

 

编程代码

 

#include<stdio.h>
#include<stdlib.h>
int main()
{int i,k,n,m,a,b,x,y,z,t,j,c;
i=1;
t=0;
b=1;
x=0;
y=0;
z=0;
k=1;
n=1;
m=1;
a=1;
c=1;
scanf("%d",&j);
n=2*j-1;
while(b<=n){x=0;
y=0;
z=0;
    
while(x<t){
    printf("\t");x++;}
while(i<=n)
{printf(" o      ");
i++;}printf("\n");
while(y<t){printf("\t");y++;}
while(k<=n){
    printf("<H>     ");k++;}
printf("\n");
while(z<t){printf("\t");z++;}
while(a<=n){
    printf("I I     ");a++;}
printf("\n");
b++;
t++;
c=c+2;
a=c;
k=c;
i=c;
}
    system("pause");

    return 0; }

运行截图

 

 

 问题

要打2n+1-2i个数

使用i-1个\t

标签:截图,include,int,scanf,实验,printf,main
From: https://www.cnblogs.com/1qq2ww3ee/p/17223583.html

相关文章

  • 实验二
    实验任务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,'*'))......
  • 实验2
    x='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,'*'))......
  • 实验二
    task1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;sra......