C语言上机练习参考答案 下载本文

内容发布更新时间 : 2024/11/15 12:26:11星期一 下面是文章的全部内容请认真阅读。

} /*程序结束时,x, y, z的值是否发生了变化?*/ Output

Please input 3 real numbers: 5 10? */ , , 5-13

/* Blue is input

输入五级制成绩(A~E),输出相应的百分制成绩(0~100)区间。五级制成

绩对应百分制程序区间为:A(90~100)、B(80~89)、C(70~79)、D(60~69)和E(0~59)。例如:输入B,输出(80~89)。 5-14

(1)用switch语句实现;(2)用if语句实现。

Program (1) #include <> main() { char grade; printf(\ scanf(\ switch (grade) { case 'A': printf(\break; case 'B': printf(\ break; case 'C': printf(\ break; case 'D': printf(\ break; case 'E': printf(\ break; default: printf(\ } } Program (2) #include <> main() { char grade; printf(\ scanf(\ if (grade=='A') printf(\ else if (grade=='B') printf(\ else if (grade=='C') printf(\ else if (grade=='D') printf(\ else if (grade=='E') printf(\ } else printf(\ Output

Please input the grade: B? 80~89 5-15

/* Blue is input */

用switch语句实现,输入数字1~7,输出对应的英文单词Monday,

Tuesday, …, Sunday。

Program #include <> main() { int day; printf(\ scanf(\ switch(day) { case 1: printf(\ case 2: printf(\break; case 3: printf(\break; case 4: printf(\break; case 5: printf(\ break; case 6: printf(\ break; case 7: printf(\break; default: printf(\ } } Output

Please input the day in a week: 4? */

Thursday 5-16 5-17 5-18 5-19 5-20 5-21

/* Blue is input

某高校的某专业录取研究生的条件如下: (1)英语成绩?55 (2)政治成绩?60 (3)专业课成绩?60

(4)以上三科的总数学成绩?200,或英语和专业课的总成绩?130。 编写程序,读入一个学生的成绩(英语、政治和专业课),判断是否可以被

录取。 Program

#include <> main() { float english, politics, professional; printf(\ scanf(\ printf(\ scanf(\ printf(\ scanf(\ if(english>=55 && politics>=60 && professional>=60 && (english+politics+professional>=200 || english+professional>=130)) printf(\ else printf(\ } Output

Please input score of English: 60? input */

Please input score of Politics: 70? is input */

Please input score of professional course: 60? is input */

Sorry, you have been rejected! 5-22 5-23 5-24 5-25 5-26 5-27 5-28 5-29 5-30

编写程序,计算下面二元方程的实数根。

ax2?bx?c?0

/* Blue is

/* Blue /* Blue

应用如下规则:

(1)如果a和b的值为零,则没有解;

(2)如果a的值为零,则只有一个解(x=-c/b); (3)如果b2-4ac为负数,则没有实数根; (4)否则,有两个实数根:

?b?b2?4acx1?

2a?b?b2?4acx2?

2a输入a, b和c的值,输出求根的情况,如有实数根,则输出实数根的值。

Program #include <> #include <> main ( ) { float a, b, c, f; printf ( \equation:\\nax*x + bx + c = 0\\n\ printf ( \ scanf ( \ printf ( \ scanf ( \ printf ( \ scanf ( \ printf ( \ if ( a == 0 && b == 0 ) printf(\ else if ( a == 0 ) printf(\ else { f = b * b - 4 * a * c; if ( f <0 ) printf(\ else printf(\ (-b + sqrt(f))/2/a, (-b - sqrt(f))/2/a ); } } Output

Please input the value of a, b and c in the quadratic equation: ax*x + bx + c = 0

a = -3? /* Blue is input */

b = 4? /* Blue is input */ c = 5? /* Blue is input */ About *x + + = 0: There are 2 real roots: , . 5-31 5-32 5-33 5-34 5-35 5-36 5-37

编写程序,读取x的值,求下面函数的值

? 1 forx?0?y??0forx?0??1forx?0?(1)用else if语句实现 (2)用嵌套if语句实现 (3)用条件运算符 ? : 实现

Program (1) #include <> main ( ) { float x; printf ( \ scanf ( \ if ( x > 0 ) printf ( \ else if ( x == 0 ) printf ( \ else printf ( \ } Program (2) #include <> main ( ) { float x; printf ( \ scanf ( \ if ( x != 0 ) /*写成if(x)是否正确?*/ { if ( x > 0 ) /*写成if(x)是否正确?*/ printf ( \ else printf ( \ } else printf ( \ } Program (3) #include <> main ( ) { float x; printf ( \ scanf ( \ printf ( \ } Output

Please input the value of x: 9? */ y = 1 5-38

/* Blue is input

某个服装展示厅宣布以下所卖物品季节性打折:

购买总额 机加工制品 0~100 无折扣 折扣 手工制品 5%