实验 7 综合练习 New

习题

一、填空:阅读下列程序说明和程序,在可选答案中,挑选一个正确答案。填补(1) (2) (3) (4)处空白,并注释说明为什么。

#include <stdio.h>
void main( )
{
    int i, b = 1;
    double s;
    s = 0 ;     /*累计加和   初始值为0*/
    for(i = 1; i <= 15; i++)
    {
        s = s + double(i)/double(b);   /*定义两个双精度浮点型变量*/ 
        b = b + 2;    /*b每次循环加2*/
    }
    printf(   "sum = %f\n"   , s);   /* 用的是%f*/
}

二、填空:阅读下列程序说明和程序,在可选答案中,挑选一个正确答案。填补(1) (2) (3) (4)处空白,并注释说明为什么。。

#include <stdio.h>
  void main( )
  {
      int i, j, t, a[10];
      printf("Enter 10 integers: ");
      for(i = 0; i < 10; i++)
          scanf( "%d", &a[i] );      /*定义数行 数组*/
      for(i = 1; i < 10; i++)
          for( j = 0 ; j < 10 - i ; j++)        /*初始为0*/
             if( a[j] < a[j+1] )             /*条件*/
             {
                 t = a[j];
                 a[j] = a[j+1];
                 a[j+1] = t;
             }
     printf("After sorted: ");
     for(i = 0; i < 10; i++)
         printf("%d ", a[i]);
     printf("\n");
}

 

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

#include<stdio.h>
#include<math.h>
int main()
{
    int x,y;
    printf("请输入X:");
    scanf("%d",&x);
    scanf("%d",&y);
    if (x<-2){
        y=x*x;
    }
    else if (x>2){
        y=sqrt(x*x+x+1);
    }
    else{
        y=x+2;
    }
    printf("y=%d",y);
        return 0;
}

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

#include<stdio.h>
int main(void)
{
    double scores;
    int x,y,z;
    x=0;
    y=0;
    z=0; 
    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;
}

 

转载于:https://www.cnblogs.com/tangxumin25/p/3398552.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值