阅读下列程序说明和C代码,把应填入其中n处的字句写在对应栏内。
【说明】
下面的程序能够计算不同图形的面积。程序中把每个图形的数据定义成结构类型,利用共同体类型描述2种图形的数据。程序根据输入参数代表的图形类型,求出图形的面积并输出。
【程序】
struct Circle
{
float x,y; /*圆心位置*/
float r; /*圆半径*/
};
struct Rectangle
{
float width; /*矩形宽*/
float length; /*矩形长*/
};
union shape
{
struct Circle circle;/*圆数据结构*/
struct Rectangle rectangle;/*矩形数据结构*/
};
main()
{
union shape a;
float area;
int i;
printf(“input number: 1circle,2rectangle,3 end\n”);
scanf("%d",&i);
while (1) /*循环接收输入,并计算输出*/
{
switch(i)
{
case 1:printf(“input radius:\n”);
scanf(“%f”, (2);/*共同体类型变量接收输入*/
area=3.1415926* (3);
printf(“the area of circle=%f\n”,area);
break;
case 2:printf(“input width and length :\n”);
seanf(“%f,%f”, (4);/*共同体类型变量接收输入*/。
area=(5);
printf(“the area of rectangle=%f\n”,area);
break;
}
printf(“input number:1 circle,2 rectangle,3 end\n”);
scanf(“%d”,&i);
}
}
第1题:
阅读下列程序说明和C++程序,把应填入其中(n)处的字句,写在对应栏内。
【说明】
阅读下面几段C++程序回答相应问题。
比较下面两段程序的优缺点。
①for (i=0; i<N; i++ )
{
if (condition)
//DoSomething
…
else
//DoOtherthing
…
}
②if (condition) {
for (i =0; i<N; i++ )
//DoSomething
}else {
for (i=0; i <N; i++ )
//DoOtherthing
…
}
第2题:
●试题二
阅读下列函数说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。
【说明】
该程序运行后,输出下面的数字金字塔
【程序】
include<stdio.h>
main ()
{char max,next;
int i;
for(max=′1′;max<=′9′;max++)
{for(i=1;i<=20- (1) ;++i)
printf(" ");
for(next= (2) ;next<= (3) ;next++)
printf("%c",next);
for(next= (4) ;next>= (5) ;next--)
printf("%c",next);
printf("\n");
}
}
第3题:
第4题:
阅读以下说明和流程图,将应填入(n)处的字句写在对应栏内。
[说明]
下面的流程图用于计算一个英文句子中最长单词的长度(即单词中字母个数)MAX。假设该英文句子中只含字母、空格和句点“.”,其中句点表示结尾,空格之间连续的字母串称为单词。
[流程图]
第5题:
试题三(共 15 分)
阅读以下说明和 C 程序,将应填入 (n) 处的字句写在答题纸的对应栏内。
第6题: