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) s=0;      

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

     8    {

     9         s = s +     (2)    double(i)/double(b)

    10         (3)    b = 2 * i 1  *由题给出的公式得出*

    11    }

    12     printf(    (4)    "sum = %f ", s);   /*结果输出不限制小数后几位所以用%*/

    13 }

    【供选择的答案】(1) As = 0 Bs = 1 Cs = -1 Ds = 2(2) Ai/b Bdouble(i)/double(b) Ci/2*i-1 D(double)i/(double)b(3) A; Bb = 2 * i – 1; Cb = 1.0 * b; Db = 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 34After 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)"%d", &a[i] );     /*输入的数字是整数*/

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

     9         for(2)j = 1(3)j < 10 - i  ; j++)

    /*相互比较、交换*/

    10             if(4)  a[j] < a[j+1] )

    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) Aj = 0 Bj = 1 Cj = i Dj = i - 1(3) Aj > i Bj < 9 - i Cj < 10 - i Dj > i - 1(4) Aa[i-1] < a[i] Ba[j+1] < a[j+2] Ca[j] < a[j+1] Da[i] < a[j]

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

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

    #include<stdio.h>
    #include<math.h>
    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{
            y=sqrt(x*x+x+1);
        }
        printf("y=%.3f
    ",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 x,y,z;
        double scores;
        
        x=0;
        y=0;
        z=0;
        /*x是优秀,y是通过,z是不及格*/
        printf("enter scores:");
        scanf("%Lf",&scores);
        
        while(scores>0){       
            if(scores>85){
                x++;
            }
            else if((scores>=60)&&(scores<=84)){
                y++;
            }
            else{
                z++;
            }
            scanf("%lf",&scores);
        }
        printf(">=85:%d",x);
        printf("60-84:%d",y);
        printf("<60:%d",z);
    
        return 0;
    }

     

     

  • 相关阅读:
    lucene初探
    直接插入排序算法(java)
    快速排序优化算法
    大根堆
    学习资料地址
    Lucene:基于Java的全文检索引擎简介
    开关按钮
    微信小程序—如何获取用户输入文本框的值
    微信小程序—获取用户网络状态和设备的信息
    Bootstrap 导航栏
  • 原文地址:https://www.cnblogs.com/liyang1995/p/3398527.html
Copyright © 2011-2022 走看看