您的位置:首页 > 其它

实验 7 综合练习 New

2013-10-31 09:47 281 查看
习题

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


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

#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: