C语言2011习题集(10)
时间:2025-07-11
时间:2025-07-11
8 为表示关系x≥y≥z,应使用C语言表达式_(x>=y)&&(y>=z)__。 9 下面的程序段的输出结果是_**3__。
int x=3;
if((x%2)?printf("**%d",x):printf("##%d\n",x));
10 以下程序运行后的输出结果是_14__。
main()
{ int m=5;
switch(m/2)
{ case 1: m++;
case 2: m+=3; case 5: m+=6;break; default: m-=7; }
printf("%d\n",m); }
三 程序填空(每空5分,共30分)
1 下列程序的输出结果是16.00,请填空。
main()
{ int a=9,b=2;
float x= 6.6 ,y=1.1,z; z=a/2+b*x/y+1/2; printf("%5.2f\n",z); }
2 完成以下程序,输入变量a,b,c的值,判断a,b,c能否组成三角形,计算三角形面积。
s p(p a)(p b)(p c)其中p (公式为:。
a b c
2
#include <stdio.h>
#include<math.h>; main()
{ int a,b,c;
float s,p;
printf("please input the value of a,b,c") scanf("%d %d %d", &a,&b,&c );
if(a+b>c && b+c>a && c+a>b && a>0 && b>0 && c>0) { p=(a+b+c)/2.0;
s=sqrt(p*(p-a)*(p-b)*(p-c));
printf("Yes,this is a triangle!\n the area is %.2f.\n",s); }
else printf("No,this is not a triangle!\n") }
循环结构程序设计
一 单项选择题(每题2分,共40分)