求助, C语言试题

有几条题目不会
请那位大哥可以帮帮忙,小弟不胜感激.定当重赏
简答题
1. 与字面常量相比,使用符号常量有哪些优点?
2. 比较continue语句和break语句的异同。
3. 以下程序段的功能是将给定的嵌套if-else语句改写成对应的switch语句,使其完成相同的功能。请填空。
if-else语句:
if (score >=90 && score < 100)
printf(“Excellent”);
else if (score >= 80)
printf(“Good”);
else if (score >= 70)
printf(“Normal”);
else if (score >= 60)
printf(“Pass”);
else
printf(“Bad”);
switch语句:
switch ()
{
()printf(“Excellent”); break;
case 8: printf(“Good”); break;
case 7: printf(“Normal”); break;
case 6: printf(“Pass”); break;
()printf(“Bad”); break;
}
4. 写出下列程序的运行结果。
#include <stdio.h>
main()
{
int a, b;
a = 20;
b = 8;
printf(“%d+%d=%d\n”, a, b, a+b);
printf(“%d-%d=%d\n”, a, b, a-b);
printf(“%d*%d=%d\n”, a, b, a*b);
printf(“%d/%d=%d\n”, a, b, a/b);
printf(“%d%%%d=%d\n”, a, b, a%b);
}
5. 写出下面程序的运行结果。
#include <stdio.h>
main()
{
int a, b, c;
a = 3;
b = -2;
c = 5;
if (a<c)
printf(“%d\n”, b);
printf(“end\n”);
}
6. 写出下面程序的运行结果。
#include <stdio.h>
main()
{
int x = 4;
do
{
printf(“%d\n”, x-=2);
}while(!(--x));
}
7. 以下程序的功能是根据输入的数据n和运算的类型t实现摄氏温度和华氏温度的换算。如果输入运算类型氏“f”或“F”,则将华氏温度转换成摄氏温度,公式为“摄氏温度=5*(华氏温度-32)/9”;如果输入的运算类型是“c”或“C”,则将摄氏温度转换成华氏温度。请填空。
main()
{
float n, result;
char t;
scanf(“%c%f”, &t, &n);
if ( )
{ result = 5 * (n – 32)/9;
printf(“the result is %f\n”, result);
}
else if ( )
{
( );
printf(“the result is %f\n”, result);
}
else
printf(“Input error.\n”);
}
编程题
1. 程序功能:用户输入数据,当输入的数不是正数时,将不显示该数,在屏幕上显示100个正数。

简答题
1. 与字面常量相比,使用符号常量有哪些优点?
答:符号常量使用更加直观。增强程序可读性。

2. 比较continue语句和break语句的异同。
答:continue结束本次循环;break跳出循环。

3. 以下程序段的功能是将给定的嵌套if-else语句改写成对应的switch语句,使其完成相同的功能。请填空。
if-else语句:
if (score >=90 && score < 100)
printf(“Excellent”);
else if (score >= 80)
printf(“Good”);
else if (score >= 70)
printf(“Normal”);
else if (score >= 60)
printf(“Pass”);
else
printf(“Bad”);
switch语句:
switch (score/10)
{
(case 9:)printf(“Excellent”); break;
case 8: printf(“Good”); break;
case 7: printf(“Normal”); break;
case 6: printf(“Pass”); break;
(default:)printf(“Bad”); break;
}

4. 写出下列程序的运行结果。
#include <stdio.h>
main()
{
int a, b;
a = 20;
b = 8;
printf(“%d+%d=%d\n”, a, b, a+b);
printf(“%d-%d=%d\n”, a, b, a-b);
printf(“%d*%d=%d\n”, a, b, a*b);
printf(“%d/%d=%d\n”, a, b, a/b);
printf(“%d%%%d=%d\n”, a, b, a%b);
}
答:20+8=28
20-8=12
20*8=160
20/8=2
20%8=4

5. 写出下面程序的运行结果。
#include <stdio.h>
main()
{
int a, b, c;
a = 3;
b = -2;
c = 5;
if (a<c)
printf(“%d\n”, b);
printf(“end\n”);
}
答:-2
end

6. 写出下面程序的运行结果。
#include <stdio.h>
main()
{
int x = 4;
do
{
printf(“%d\n”, x-=2);
}while(!(--x));
}
答:2

7. 以下程序的功能是根据输入的数据n和运算的类型t实现摄氏温度和华氏温度的换算。如果输入运算类型氏“f”或“F”,则将华氏温度转换成摄氏温度,公式为“摄氏温度=5*(华氏温度-32)/9”;如果输入的运算类型是“c”或“C”,则将摄氏温度转换成华氏温度。请填空。
main()
{
float n, result;
char t;
scanf(“%c%f”, &t, &n);
if ('f'==t||'F'==t)
{ result = 5 * (n – 32)/9;
printf(“the result is %f\n”, result);
}
else if ('c'==t||'C'==t )
{
( result=(9*n)/5+32);
printf(“the result is %f\n”, result);
}
else
printf(“Input error.\n”);
}

编程题
1. 程序功能:用户输入数据,当输入的数不是正数时,将不显示该数,在屏幕上显示100个正数。
#include <stdio.h>

void main()
{
int n=0,i=0;
while (i<100)
{
scanf("%d", &n);
if (n>0)
printf("No.%d: %d \n",i,n);
i++;
}
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-12-18
1改错:首先Printf
,Exit
,Double,C语言没有大写的定义。还有就是scanf(“f%
f%
f%”,&a,&b,&c);%f
%f
%f
而不是f%。
2改错:
首先还是大写问题:char
s1[5],s2[20]);多了一个“)”。
Ustrcat(char
s1[],char
s2[]);定义的时候大写,这里
puts(ustrca(s1,s2));用小写而且还少一个t字母。
while(s2[k]
=’\0’)应该是!=号吧!!
程序你己自写的吧一,般卷子上不会问这样的问题。
2________________________________________________________
1.编写程序,根据以下公式求e的值。要求用两种方法进行计算:(1)用for循环,计算前50项。(2)用while循环,要求直至最后一项的值小于10-4。(程序命名为2_1.c)
看不明白计算前50项的和?差?平方和?。。。。。不知道要干什么。
(2)用while循环,要求直至最后一项的值小于10-4。什么意思???
哪到哪
就最有一项了?怎么个算法啊?小于10小于4还是小于6?
公式
看不到
-------------------------------------------------------------
2
#include
<stdio.h>
#define
N
5
int
main(void)
{
int
anArr[N][N];
int
iRow,
iLIne;
for
(iRow
=
0;
iRow
<
N;
++iRow)
{
for
(iLIne
=
0;
iLIne
<
N;
++iLIne)
{
printf("输入anArr[%d][%d]位置上的数字:",
iRow,
iLIne);
scanf("%d",
&anArr[iRow][iLIne]);
}
}
for
(iRow
=
0;
iRow
<
N;
++iRow)
{
for
(iLIne
=
iRow;
iLIne
<
N;
++iLIne)
anArr[iRow][iLIne]
=
0;
}
for
(iRow
=
0;
iRow
<
N;
++iRow)
{
for
(iLIne
=
0;
iLIne
<
N;
++iLIne)
printf("%d\t",
anArr[iRow][iLIne]);
printf("\n");
}
return
0;
}
---------------------------------------------------------
3
#include
<stdio.h>
#define
N
20
int
nMax,
nMin;
int
GetMean(int
anResults[])
{
int
iRow;
int
nMean
=
0;
nMean
=
nMax
=
nMin
=
anResults[0];
for
(iRow
=
1;
iRow
<
N;
++iRow)
{
if
(nMax
<
anResults[iRow])
nMax
=
anResults[iRow];
if
(nMin
>
anResults[iRow])
nMin
=
anResults[iRow];
nMean
+=
anResults[iRow];
}
return
nMean
/
N;
}
int
Sort(int
anResults[])
{
int
iRow,
iRowNext,
nTemp;
for
(iRow
=
0;
iRow
<
N;
++iRow)
{
for
(iRowNext
=
iRow
+
1;
iRowNext
<
N;
++iRowNext)
{
if
(anResults[iRow]
<
anResults[iRowNext])
{
nTemp
=
anResults[iRow];
anResults[iRow]
=
anResults[iRowNext];
anResults[iRowNext]
=
nTemp;
}
}
}
return
0;
}
int
main(void)
{
int
anResults[N];
int
iRow;
int
nMean
=
0;
for
(iRow
=
0;
iRow
<
N;
++iRow)
{
printf("输入第%d学的成绩:",
iRow);
scanf("%d",
anResults
+
iRow);
}
nMean
=
GetMean(anResults);
printf("MAX=%d\nMIN=%d\nMEAN=%d\n",
nMax,
nMin,
nMean);
Sort(anResults);
for
(iRow
=
0;
iRow
<
N;
++iRow)
{
printf("%d\t",
anResults[iRow]);
}
printf("\n");
return
0;
}
第2个回答  2007-12-12
1. 用一个标识符代表一个常量的符号称为符号常量,在一个比较复杂的程序中,利用符号常量,与用字面常量相比,修改时一改全改,会方便许多,例如:
#define PI 3.1415926
在下面程序中PI即代表3.1415926,要改程序中这值时(例改为3.14),只要到这里改就好,而用字符常量(例3.1415962)要改时则每个都要改。
2.break只能用于循环语句和switch中,在循环体中执行break语句是结束整个循环体,而不是单纯的break所在循环。而continue语句只结束本次即它所在的循环,然后判断下一个循环,continue可用一个判断句替换,主要是起强调作用。
第3个回答  2007-12-12
不会
相似回答