首页 > 其他分享 >实验2

实验2

时间:2023-10-19 09:33:07浏览次数:25  
标签:space int -- 实验 printf include

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

实验任务1源代码如上

实验任务1运行结果

问题1思考

 line 17功能是从N1到N2间随机生成一个数字

问题2思考

 随机生成五个学号(可以用来随机点名)

实验2源代码

 1 #include<stdlib.h>
 2 
 3 int main()
 4 {
 5     char color;
 6     
 7     while(scanf("%c",&color)!=EOF) 
 8     {
 9         if (color>='a'&&color<='z')
10         {
11             if (color=='r')
12                 printf("stop\n");
13             else if (color=='g')
14                 printf("go,go,go\n");
15             else if (color=='y')
16                 printf("wait a minute\n");
17             else
18                 printf("something must be wrong");
19         }
20         
21     }
22     return 0;
23 }

实验2运行结果

 

实验3源代码

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 
 4 #define D1 1
 5 #define D2 30
 6 
 7 int main()
 8 {
 9     int day;
10     int i;
11     int c=0;
12     int a=1;
13     printf("猜猜20233年11月哪一天会是你的lucky day\n");
14     printf("开始喽,你有三次机会,猜吧(1~30):");
15     
16     day = rand()%(D2-D1+1)+D1;
17     for(c=3;c>0;c--)
18     {    
19         a=i-1;
20         scanf("%d",&i);
21         if(i<day)
22         {
23             printf("你猜的日期太早了,你的lucky day还没到呢\n");
24             printf("再猜(1~30):");
25         }
26         else if(i>day)
27         {
28             printf("你猜的日期晚了,你的lucky day已经过啦\n");
29             printf("再猜(1~30):");
30         }
31         else if(i==day)
32             printf("哇,猜对了!");
33     }
34     return 0; 
35 }

实验3运行结果

 

实验4源代码

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

实验4运行结果

 

实验5源代码

 1 #include<stdio.h>
 2 
 3 int main()
 4 {
 5     int i,j;
 6     for(i=1;i<=9;i++)
 7     {
 8         for(j=1;j<=i;j++)
 9         {
10             printf("%d*%d=%-3d ",j,i,j*i);
11         }
12         printf("\n");
13     }
14     return 0;
15     
16 }

实验5运行结果

 

实验6源代码

 

 1 #include<stdio.h>
 2 
 3 int main()
 4 {
 5     int n;
 6     scanf("%d", &n);
 7     int n1 = n;
 8     int s;
 9     int space;
10 
11     for (n = n; n > 0; n--) {
12         for (space = n1 - n; space > 0; space--) {
13             printf("\t");
14         }
15         for (s = 2 * n - 1; s > 0; s--) {
16             printf(" o\t");
17         }
18         printf("\n");
19 
20 
21         for (space = n1 - n; space > 0; space--) {
22             printf("\t");
23         }
24         for (s = 2 * n - 1; s > 0; s--) {
25             printf("<H>\t");
26         }
27         printf("\n");
28 
29 
30         for (space = n1 - n; space > 0; space--) {
31             printf("\t");
32         }
33         for (s = 2 * n - 1; s > 0; s--) {
34             printf("I I\t");
35         }
36         for (space = n1 - n; space > 0; space--) {
37             printf("\t");
38         }
39         printf("\n");
40     }
41 
42     return 0;
43 }

 

实验6运行结果

 

 

标签:space,int,--,实验,printf,include
From: https://www.cnblogs.com/almost2223/p/17767923.html

相关文章

  • 实验1 类和对象
     #include<iostream>#include<string>#include<vector>#include<array>template<typenameT>voidoutput1(constT&obj){for(autoi:obj)std::cout<<i<<",";std::cout<<"\b\b......
  • 实验二
    一、实验二作业①:要求:在中国气象网(http://www.weather.com.cn)给定城市集的7日天气预报,并保存在数据库。输出信息序号地区日期天气信息温度1北京7日(今天)多云转晴31℃/17℃2北京8日(明天)晴34℃/20℃3北京9日(后天)多云转晴32℃/19℃4北京10日(......
  • 实验2 C语言分支与循环基础应用编程
    实验任务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-N......
  • 钉钉圈子群用于实验室辅助管理
    其实前面一直用企业微信管理实验室的,疫情期间企业微信未认证的人数上限是500,也差不多够用了。上半年开始企业微信开始弹认证提醒了,提示人数不能超100,然后就发现很多新加的学生无法发送信息了,审批功能倒还是能用,就是不能聊天。微信群、freeflarum免费论坛、兔小巢、QQ频道,学生都没......
  • 实验1 类和对象_基础编程1
    实验任务1task1.cpp1//标准库string,vector,array基础用法23#include<iostream>4#include<string>5#include<vector>6#include<array>78//函数模板9//对满足特定条件的序列类型T对象,使用范围for输出10template<typenameT>11v......
  • 实验二 Linux命令使用(二)
    实验内容及步骤:(1)进入家目录,创建自己的子目录,进入该子目录,运行date>file1,然后运行catfile1,看到什么信息?“>”是什么符号?答:输出重定向操作符解释“date>file1”的含义:答:将当前日期和时间写入名为file1的文件中。(2)运行mandate>>file1,再运行catfile1,看到什么?mandat......
  • OSPF不同网络类型建立邻居实验
    个人名片:......
  • 【OSPF宣告——network命令与多区域配置实验案例】
    个人名片:......
  • 实验2
    实验1 源代码1#include<stdio.h>2#include<stdlib.h>3#include<time.h>4#defineN55#defineN13746#defineN24657intmain()8{9intnumber;10inti;1112srand(time(0));1314for(i=0;i<N;++i)15{......
  • 实验1 类和对象
     task1.cpp#include<iostream>#include<string>#include<vector>#include<array>template<typenameT>voidoutput1(constT&obj){for(autoi:obj)std::cout<<i<<",";std::cout<<"......