C语言全部题目及答案

2020-04-18 02:39

C语言全部题目及答案

Exercise 1: Programming Environment and Basic Input/Output

1. Write a program that prints “This is my first program!” on the screen.

(a) Save this program onto your own disk with the name of e2-1a; (b) Run this program without opening Turbo C;

(c) Modify this program to print “This is my second program!”, then save it as

e2-1b. Please do not overwrite the first program.

2. Write a program that prints the number 1 to 4 on the same line. Write the program using the following methods:

(a) Using four “printf” statements.

(b) Using one “printf” statement with no conversion specifier (i.e. no ?%?). (c) Using one “printf” statement with four conversion specifiers

3.(a) Write a program that calculates and displays the number of minutes in 15 days. (b) Write a program that calculates and displays how many hours 180 minutes equal to.

(c) (Optional) How about 174 minutes?

ANSWERS: #include int main() { printf(\is my first program!\ return 0; } #include int main() { printf(\is my second program!\ return 0; } #include int main() { printf(\printf(\printf(\printf(\ return 0; } #include int main() { printf(\ return 0; #include int main() { float days,minutes; days = 15; minutes = days * 24 * 60; printf(\number of minutes in 15 days are %f\\n\ return 0; } #include int main() { float minutes,hours; minutes = 180; } #include int main() { printf(\ return 0; } hours = minutes / 60; printf(\minutes equal to %f hours\\n\ return 0; } #include int main() { float minutes,hours; minutes = 174; hours = minutes / 60; printf(\minutes equal to %f hours\\n\ return 0; }

Exercise 2: Data Types and Arithmetic Operations

1. You purchase a laptop computer for $889. The sales tax rate is 6 percent. Write and execute a C program that calculates and displays the total purchase price (net price + sales tax).

2.Write a program that reads in the radius of a circle and prints the circle?s diameter, circumference and area. Use the value 3.14159 for “?”.

3.Write a program that reads in two numbers: an account balance and an annual interest rate expressed as a percentage. Your program should then display the new balance after a year. There are no deposits or withdraws – just the interest payment. Your program should be able to reproduce the following sample run:

Interest calculation program. Starting balance? 6000

Annual interest rate percentage? 4.25 Balance after one year: 6255

ANSWER:

#include

int main() {

float net_price,sales_tax,total; net_price = 889;

sales_tax = net_price * 0.06; total = net_price + sales_tax;

printf(\

return 0; }

#include int main() {

printf(\float radius,diameter,circumference,area; scanf(\

printf(\

printf(\printf(\

return 0; }

#include int main() {

float SB,percentage,NB;

printf(\scanf(\

printf(\scanf(\

NB = SB * percentage / 100 + SB;

printf(\

return 0; }

Exercise 3: Selection structure

1.

2. 3.

Write a C program that accepts a student?s numerical grade, converts the numerical grade to Passed (grade is between 60-100), Failed (grade is between 0-59), or Error (grade is less than 0 or greater than 100).

Write a program that asks the user to enter an integer number, then tells the user whether it is an odd or even number.

Write a program that reads in three integers and then determines and prints the largest in the group.

ANSWER:

#include

#include int main() { int grade; printf(\ scanf(\ if (grade >= 60 && grade <= 100) printf(\ else if (grade >= 0 && grade <60) printf(\ else printf(\ return 0; } #include int main() { int a,b,c; printf(\ printf(\ scanf(\ if (a > b && a > c) printf(\ else if (b > a && b > c) printf(\ else if (c > a && c > b) printf(\ else printf(\ return 0; } #include

int main() {

int a;

printf(\

printf(\

scanf(\ if (a%2 == 0)

printf(\ else

printf(\ return 0; }

Exercise 4: ?switch? statement and simple “while” repetition statement

1. Write a program that reads three integers an abbreviated date (for example: 26 12 94) and

that will print the date in full; for example: 26th December 1994. The day should be followed by an appropriate suffix, ?st?, ?nd?, ?rd? or ?th?. Use at least one switch statement.

2.Write a C program that uses a while loop to calculate and print the sum of the even integers from 2 to 30.

3. A large chemical company pays its sales staff on a commission basis. They receive £200 per week plus 9% of their gross sales for that week. For example, someone who sells £5000 of chemicals in one week will earn £200 plus 9% of £5000, a total of £650. Develop a C program that will input each salesperson?s sales for the previous week, and print out their salary. Process one person?s figures at a time.

Enter sales in pounds (-1 to end): 5000.00 Salary is: 650.00

Enter sales in pounds (-1 to end): 00.00 Salary is: 200.00

Enter sales in pounds (-1 to end): 1088.89 Salary is: 298.00

Enter sales in pounds (-1 to end): -1

Optional:

4. A mail order company sells five different products whose retail prices are shown in the

following table:

Product Number Retail Price (in pounds) 1 2.98 2 4.50


C语言全部题目及答案.doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:毛泽东思想与中国特色社会主义理论体系概论实践选题

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: