• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
唐旭敏
博客园    首页    新随笔    联系   管理    订阅  订阅

实验 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)、通过(60~84)和不及格(小于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;
}

 

posted @ 2013-10-31 09:47  唐旭敏  阅读(222)  评论(2)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3