zoukankan      html  css  js  c++  java
  • 实验7 ——综合练习

    实验目的:巩固分支结构、循环结构、函数和数组的使用方法。
    习题

    一、填空:阅读下列程序说明和程序,在可选答案中,挑选一个正确答案。填补(1) (2) (3) (4)处空白,并注释说明为什么。
    程序说明
    求 1 + 2/3 + 3/5 + 4/7 + 5/9 + … 的前15项之和。
    运行示例:
    sum = 8.667936
    程序如下:

     

     1 #include <stdio.h>

     2 void main( )

     3 {

     4     int i, b = 1;

     5     double s;

     6     (1)    ;

     7     for(i = 1; i <= 15; i++)

     8     {

     9         s = s +     (2)   

    10         (3)   

    11     }

    12     printf(    (4)    , s);

    13 }

     

    【供选择的答案】
    (1)   A、s = 0       B、s = 1       C、s = -1       D、s = 2
    (2)   A、i/b                           B、double(i)/double(b)
           C、i/2*i-1                     D、(double)i/(double)b
    (3)   A、;                             B、b = 2 * i – 1; 
           C、b = 1.0 * b;             D、b = b + 2;
    (4)   A、"sum = %d "          B、"s = %c "
           C、"sum = %f "           D、"s = %s "

    ---------------------------------题目分割线-----------------------------------

    二、填空:阅读下列程序说明和程序,在可选答案中,挑选一个正确答案。填补(1) (2) (3) (4)处空白,并注释说明为什么。。
    【程序说明】
    输入10个整数,将它们从大到小排序后输出。
    运行示例:
    Enter 10 integers: 1 4 -9 99 100 87 0 6 5 34
    After sorted: 100 99 87 34 6 5 4 1 0 -9
    程序如下:

     

     1 #include <stdio.h>

     2 void main( )

     3 {

     4     int i, j, t, a[10];

     5     printf("Enter 10 integers: ");

     6     for(i = 0; i < 10; i++)

     7         scanf( (1) );

     8     for(i = 1; i < 10; i++)

     9         for( (2) ; (3) ; j++)

    10             if( (4) )

    11             {

    12                 t = a[j];

    13                 a[j] = a[j+1];

    14                 a[j+1] = t;

    15             }

    16     printf("After sorted: ");

    17     for(i = 0; i < 10; i++)

    18         printf("%d ", a[i]);

    19     printf(" ");

    20 }

     

    【供选择的答案】

    (1) A、"%f", a[i]          B、"%lf", &a[i]           C、"%s", a              D、"%d", &a[i] 
    (2) A、j = 0                B、j = 1                    C、j = i                   D、j = i - 1
    (3) A、j > i                 B、j < 9 - i                C、j < 10 - i            D、j > i - 1
    (4) A、a[i-1] < a[i]      B、a[j+1] < a[j+2]     C、a[j] < a[j+1]       D、a[i] < a[j]

    ---------------------------------题目分割线-----------------------------------

    三、编程,输入x后,根据下式计算并输出y值。

     

    #include<stdio.h>

    #include<math.h>

    int main(void)

    {

          double x,y;  

          printf("Enter x:");

          scanf("%lf",&x);

          if(x<-2){

               y=x*x;

          }

          else if((x>=-2)&&(x<=2)){

               y=2+x;

          }

          else(x>2){

              

               y=sqrt(x*x+x+1);

          }

          printf("y=%lf",y);

          return 0;

    }

    ---------------------------------题目分割线-----------------------------------

    四、编写程序,输入一批学生的成绩,遇0或负数则输入结束,要求统计并输出优秀(大于85)、通过(6084)和不及格(小于60)的学生人数。

    运行示例:

    Enter scores: 88 71 68 70 59 81 91 42 66 77 83 0

    >=85:2

    60-84:7

    <60   : 2

    #include<stdio.h>

    int main(void)

    {

           int good,pass,nopass,i,grade;

          

           good=0;

           pass=0;

           nopass=0;

          

           for(i=1;i<=5;i++){

                  printf("Enter 5 grades:");

               scanf("%d",&grade);

                  if(grade>=85){

                         good++;

                  scanf("%d",&grade);

                  }

                  else if(grade>60&&grade<84){

                         pass++;

                  scanf("%d",&grade);

                  }

                  else{

                         nopass++;

                  scanf("%d",&grade);

                  }

                  printf("good=%d ",good);

                  printf("pass=%d ",pass);

                  printf("nopass=%d ",nopass);     }

                 

           return 0;

    }

  • 相关阅读:
    Redis 设计与实现 2:Redis 对象 redisObject
    Redis 设计与实现 1:数据库 redisDb
    KafkaProducer 简析
    G1 收集器
    KafkaMirrorMaker 的不足以及一些改进
    Redis 数据结构与对象编码 (Object Encoding)
    跨境 TCP 传输优化实录 — 使用 BBR 解决 LFN 问题
    TCP 协议简析
    使用模拟退火算法优化 Hash 函数
    LSM-Tree 与 B-Tree
  • 原文地址:https://www.cnblogs.com/xym0914/p/3398579.html
Copyright © 2011-2022 走看看