实验七综合练习

//                 编程,输入x后,根据下式计算并输出y值。
#include<stdio.h>
#include<math.h>
int main()
{
    double x,y;
    printf("enter x:");
    scanf("%lf",&x);
    
    if(x<-2){
        y=x*x;
    }
        else if(x<=2) {
            y=2+x;
          }
          else{
            y=sqrt(x*x+x+1);
          }
          printf("y=%lf",y);

          return 0;
}

 

 

 

           //           编写程序,输入一批学生的成绩,遇0或负数则输入结束,要求统计并输出优秀(大于85)、通过(60~84)和不及格(小于60)的学生人数
#include<stdio.h>
int main()
{
    int x,a,b,c;

    printf("enter x:");
    scanf("%d",&x);
    a=0;
b=0;
c=0;
while(x>0){ if(x>85){ a++; } else if(x<60){ b++; } else{ c++; } scanf("%d",&x); } printf("优秀=%d\n",a); printf("通过=%d\n",c); printf("不及格=%d\n",b); return 0; }

 

 

一、填空:阅读下列程序说明和程序,在可选答案中,挑选一个正确答案。填补(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)  A  ;//赋初值

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

 8     {

 9         s = s + B    (2)   //改变数据类型

10         (3)    D//计算函数

11     }

12     printf(    (4) C   , s);//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\n"          B、"s = %c\n"
       C、"sum = %f\n"           D、"s = %s\n"

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

二、填空:阅读下列程序说明和程序,在可选答案中,挑选一个正确答案。填补(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)D );//输入整型数组

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

 9         for( (2)A ; (3)C ; j++)//j为变量进行排序

10             if( (4)C )//对数据比较排序

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("\n");

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值。

 

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

四、编写程序,输入一批学生的成绩,遇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

 

posted @ 2013-10-31 09:48  刘丽娜123456  阅读(169)  评论(1编辑  收藏  举报