c语言编程全部练习

上传人:大米 文档编号:486087264 上传时间:2024-02-13 格式:DOCX 页数:7 大小:36.41KB
返回 下载 相关 举报
c语言编程全部练习_第1页
第1页 / 共7页
c语言编程全部练习_第2页
第2页 / 共7页
c语言编程全部练习_第3页
第3页 / 共7页
c语言编程全部练习_第4页
第4页 / 共7页
c语言编程全部练习_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《c语言编程全部练习》由会员分享,可在线阅读,更多相关《c语言编程全部练习(7页珍藏版)》请在金锄头文库上搜索。

1、命名 文件和邮件名相同 压缩包内文件无所谓在下周二上课前交Exercise 1: Programming Environment and Basic Input/Output1. 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 prin

2、t“This is my second program! ” , then save it ase2-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) Usingfour“printfstatements.(b) Using one“printf“statement wonversion specifier no %).(

3、c) Using one“ printf“statement with four conversion specifiers3. (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 minutesExercise 2: Data Types and Arith

4、metic Operations1. 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 ancprints the circle s diameter, circumfere

5、nce and area. Use thevalue 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

6、 be able to reproduce the following sample run:Interest calculation program.Starting balance6000Annual interest rate percentageBalance after one year:Exercise 3: Selection structure1. Write a C program that accepts a student s numerical grade, converts the numerical grade to Passed (grade is between

7、 60-100), Failed (grade is between 0-59), or Error (grade is less than 0 or greater than 100).2. Write a program that asks the user to enter an integer number, then tells the user whether it is an odd or even number.3. Write a program that reads in three integers and then determines and prints the l

8、argest in the group.Exercise 4 switchstatemdestmple whilerepetition statement1. Write a program that reads three integers an abbreviated date (for example: 26 12 94) andthat will print the date in full; for example: 26th December 1994. The day should be followedby an appropriate suffix, st , nd , rd

9、 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 perweek plus 9% of their gross sales for that week. For exa

10、mple, someone who sells 5000 ofchemicals in one week will earn 200 plus 9% of 5000, a total of 650. Develop a C program that will input each salesperson 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):Salary is:Enter s

11、ales in pounds (-1 to end):Salary is:Enter sales in pounds (-1 to end):Salary is:Enter sales in pounds (-1 to end): -1Optional :两重的 while4. A mail order company sells five different products whose retail prices are shown in the following table:Product NumberRetail Price (in pounds)Write a C program

12、that reads in a series of pairs of numbers as follows:(1) . Product number(2) . Quantity sold for one dayYour program should use a switch statement to help determine the retail price for each product, and should use a sentinel-controlled loop to calculate the total retail value of all products sold

13、in a given week (7days).Exercise 5: forad d do while“ repetition statements1. Write a program which uses a do/while loop to print out the first 10 powers of 2 other than 0 (ie. it prints out the values of 2 1, 22, ., 210). Use a for loop to do the same.2. The constant can be calculated by the infini

14、te series:= 4 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11 +Write a C program that uses a do/while loop to calculate using the series. The program should ask the user how many terms in the series should be used. Thus if the user enters the program should calculate as being 4 - 4/3 + 4/5.Nested repetition3. Write

15、a program that prints the following diamond shape. You may use printf statements that print either a single asterisk (*) or a single blank. Maximize your use of repetition (with nested for statements) and minimize the number of printf statements.*4. Write a program to print a table as follows:1*1= 12*1= 23*1= 32*2= 43*2= 6 3*3= 99*1= 9 9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=81Exercise 6: Simple Functions1. Write a C program that reads several numbers and uses the function round_to_nearest to round each of these numbers to the ne

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 商业/管理/HR > 营销创新

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号