首页 > 其他分享 >实验2

实验2

时间:2023-10-17 23:25:44浏览次数:22  
标签:include int number 实验 printf 源代码

实验1 源代码

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <time.h>
 4 #define N 5
 5 #define N1 374
 6 #define N2 465
 7 int main()
 8 {
 9  int number;
10  int i;
11  
12  srand(time(0));
13  
14  for(i = 0; i < N;++i)
15  {
16   number = rand()%(N2 - N1 + 1) + N1;
17   printf("202383290376%04d\n",number);
18  }
19  
20  return 0;
21 }

 

实验一 截屏

 

实验二 源代码

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 int main()
 4 {
 5  char colour;
 6  
 7  while(scanf("%c",&colour) != EOF)
 8  {
 9   switch (colour)
10   {
11    case 'r': printf("stop!");break;
12    case 'g': printf("go go go");break;
13    case 'y': printf("wait a minute");break;
14    default : printf("something must be wrong");break;
15   }
16  }
17  
18  system("pause");
19  return 0;
20 }

 

实验二 截屏

 

实验三 源代码

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <time.h>
 4 int main()
 5 {
 6  int number, count, a;
 7  srand(time(0));
 8  number = rand() % 30 + 1;
 9  count = 3;
10  a = 0;
11  printf("猜\n");
12  
13  do
14  {
15   scanf("%d",&a);
16   count --;
17   if( a > number )
18    printf("晚\n");
19   else if( a < number )
20    printf("早\n");
21  }while (a != number && count > 0 );
22  
23  if( a == number )
24      printf("对\n");
25  else if(count == 0)
26   printf("是%d号",number);
27  
28  system("pause");
29  return 0;
30 }

 

实验三 截屏

 

 

实验四 源代码

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 int main()
 4 {
 5  int n, a, i, d;
 6  double s;
 7  d = 1;
 8  s = 0;
 9  
10  while (scanf("%d %d",&n,&a) != EOF)
11  {
12      for (i = 1;i <= n;i++)
13    {
14      d *= a;
15      s += i*1.0/d;
16    }
17    printf("n = %d, a = %d, s = %.7f\n",n,a,s);
18    d = 1, s = 0, i = 1;
19  }
20  
21  system("pause");
22  return 0;
23 }

 

实验四 截屏

 

实验五 源代码

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 int main()
 4 {
 5  int line, first;
 6  line = 1;
 7  first = 1;
 8  
 9  for (line = 1;line <= 9;line++)
10  {
11      for (first = 1;first <= line;first++)
12   {
13      i = first*line;
14      printf("%dx%d = %d ",first,line,i);
15   }
16   printf("\n");
17  }
18  
19  system("pause");
20  return 0;
21 }

 

实验五 截屏

 

实验六 源代码

 

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 int main()
 4 {
 5  int n, i, m;
 6  i = 0;
 7  m = 0;
 8  
 9  scanf("%d",&n);
10  
11  while (n > 0)
12  {
13      for (i = 0;i < m;i++)
14      {
15          printf("      ");
16      }
17     
18     for (i = 0;i <= 2*(n-1);i++)
19     {
20         printf(" o    ");
21     }
22     
23     printf("\n");
24     
25     for (i = 0;i < m;i++)
26      {
27          printf("      ");
28      }
29     
30     for (i = 0;i <= 2*(n-1);i++)
31     {
32         printf("<H>   ");
33     }
34     
35     printf("\n");
36     
37     for (i = 0;i < m;i++)
38      {
39          printf("      ");
40      }
41     
42     for (i = 0;i <= 2*(n-1);i++)
43     {
44         printf("I I   ");
45     }
46     printf("\n");
47     
48     n--;
49     m++;
50  }
51  
52  system("pause");
53  return 0;
54 }

 

实验六 截屏

 

 

标签:include,int,number,实验,printf,源代码
From: https://www.cnblogs.com/7perch/p/17769673.html

相关文章

  • 实验1 类和对象
     task1.cpp#include<iostream>#include<string>#include<vector>#include<array>template<typenameT>voidoutput1(constT&obj){for(autoi:obj)std::cout<<i<<",";std::cout<<"......
  • 实验1
    试验任务1task1.cpp源码//标准库string,vector,array基础用法#include<iostream>#include<string>#include<vector>#include<array>//函数模板//对满足特定条件的序列类型T对象,使用范围for输出template<typenameT>voidoutput1(constT&obj){for......
  • 实验2
    实验任务1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineN1374#defineN2465intmain(){intnumber;inti;srand(time(0));for(i=0;i<N;++i){number=rand()%(N2-N1+1)+N1;printf("202......
  • 实验2
     问题1:确保输出的数值在374-465之间问题2:输出4个“学号+0+三位随机数”形式的随机数值#define_CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineN1374#defineN2465intmain(){intnumber;inti;......
  • 【产品有效期验证之加速实验方法】
    使用期限:大于等于5年评价路径:整机测试临床使用模式:贮存、待机、运行加速环境实验:是一种激发实验,通过强化应力环境来进行可靠性实验。加速水平通常用加速因子来体现。加速因子:设备正常工作应力下寿命与加速环境下的寿命之比。使用工具:环境实验箱1、温度加速因子(TAF)Arrhenius模型计......
  • 实验一
    #include<iostream>#include<string>#include<vector>#include<array>template<typenameT>voidoutput1(constT&obj){for(autoi:obj)std::cout<<i<<",";std::cout<<"\b\b\......
  • 实验五 队列的基本操作及应用
    实验五队列的基本操作及应用作业要求:实验时间:第7、8周实验目的:掌握队列的初始化、判空、取队头元素、出队、入队、输出队列元素等基本操作实验要求:1、认真阅读和掌握教材上和本实验相关的算法。2、上机将链队列或循环队列的相关算法实现。3、实现下面实验内容要求的功能,并......
  • 实验一 类与对象_基础编程1
    task1.cpp1#include<iostream>2#include<string>3#include<vector>4#include<array>56template<typenameT>7voidoutput1(constT&obj){8for(autoi:obj)9std::cout<<i<<","......
  • 实验2
    任务一源代码 任务一运行结果 任务一问题回答 任务二源代码  任务二运行结果 任务三源代码  任务三运行结果 任务四源代码  任务四运行结果  任务五源代码  任务五运行结果  任务六源代码  任务六运行结果 ......
  • 实验一
    #include<iostream>#include<string>#include<vector>#include<array>//函数模板//对满足特定条件的序列类型T对象,使用范围for输出template<typenameT>voidoutput1(constT&obj){for(autoi:obj)std::cout<<i<<",";......