1、最新C语言全部题目及答案C语言全部题目及答案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 print “Thi
2、s 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
3、 (i.e. no %).(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 minutes?ANSWERS:#include
4、int main()printf(This is my first program!);return 0;#includeint main()printf(This is my second program!);return 0;#includeint main()printf(1);printf(2);printf(3);printf(4);return 0;#includeint main()printf(1234);return 0;#includeint main()printf(%d%d%d%d,1,2,3,4);return 0;#includeint main()float da
5、ys,minutes;days = 15;minutes = days * 24 * 60;printf(The number of minutes in 15 days are %fn, minutes);return 0;#includeint main()float minutes,hours;minutes = 180;hours = minutes / 60;printf(180 minutes equal to %f hoursn, hours);return 0;#includeint main()float minutes,hours;minutes = 174;hours =
6、 minutes / 60;printf(174 minutes equal to %f hoursn, hours);return 0;Exercise 2: Data Types and Arithmetic 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
7、).2Write a program that reads in the radius of a circle and prints the circles diameter, circumference and area. Use the value 3.14159 for “”.3Write 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
8、 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? 6000Annual interest rate percentage? 4.25Balance after one year: 6255ANSWER:#includeint main()float ne
9、t_price,sales_tax,total;net_price = 889;sales_tax = net_price * 0.06;total = net_price + sales_tax;printf(The total purchase price is %g, total);return 0;#includeint main()printf(Please input a number as radius:n);float radius,diameter,circumference,area;scanf(%f,&radius);printf(The diameter is %gn,
10、diameter = radius * 2);printf(The circumference is %gn,circumference = radius * 2 * 3.14159);printf(The area is %gn, area = radius * radius * 3.14159);return 0;#includeint main()float SB,percentage,NB;printf(Interest calculation programnnPlease enter the Starting Balance:);scanf(%f,&SB);printf(Pleas
11、e enter the Annual interest rate percentage:);scanf(%f,&percentage);NB = SB * percentage / 100 + SB;printf(nThe Balance after one year is:%g,NB);return 0;Exercise 3: Selection structure1 Write a C program that accepts a students numerical grade, converts the numerical grade to Passed (grade is betwe
12、en 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
13、largest in the group.ANSWER:#includeint main() int grade; printf(Please enter the grade:); scanf(%d,&grade); if (grade = 60 & grade = 0 & grade 60) printf(Failed.); else printf(Error.); return 0;#includeint main() int a,b,c; printf(Please enter 3 integer numbersn); printf(Then Ill tell you which is
14、the largestn); scanf(%d%d%d,&a,&b,&c); if (a b & a c) printf(%d is the largest,a); else if (b a & b c) printf(%d is the largest,b); else if (c a & c b) printf(%d is the largest,c); else printf(Theyre equal); return 0;#include#includeint main() int a; printf(Please enter an integer numbern); printf(Then Ill tell you whether its an odd or even number); scanf(%d,&a); if (a%2 = 0) printf(%d is an even number,a); else
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1