Beruflich Dokumente
Kultur Dokumente
2. Input the base and height of a triangle and output its area. A = (1/2)BH
3. Input the length and width of a rectangle and output its area and perimeter.
4. Input the radius of the circle and output its area and circumference.
5. Compute the geometric mean G of two positive numbers A and B, where the geome
tric mean is the square root of the product of the two numbers.
6. Given the price of an item bought on sale. Subtract the discount percentage f
rom the original price and print the new price.
7. Input your weight in pounds and output your weight in kilograms.
8. Input a month between 1 and 12 and output "January", "February",... or "Decem
ber". Furthermore, if month is not between 1 and 12, output an "Error". Solve us
ing nested if and using switch.
9. A bond paying 4 1/2 % compounded semi-annually is bought for P20,000.00; how
much will it be worth when it matures 15 years from now?
10. The area of any triangle can be calculated from the lengths of its sides by
using the following formula:
s = (a + b + c)/ 2.0;
t_area = sqrt(s*(s-a)*(s-b)*(s-c));
11. Print all odd numbers between 1 to n, inclusive.
12. Print all even numbers between 1 to n, inclusive.
13. Print all multiple of 3 between 1 to 100, inclusive.
14. Prepare a program to produce the following:
a.
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
b.
5
5 4
5 4 3
5 4 3 2
5 4 3 2 1
c.
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
d.
5 4 3 2 1
5 4 3 2
5 4 3
5 4
5
15. Write a program to calculate the sum: 1 + 1/2 + 1/3 + 1/4 + ... + 1/n, where
n is the number of terms specified by the user. This sum is called harmonic ser
ies.
16. Like in #15, write a program to calculate the geometric series.
17. Write a program to read in a distance expressed in kilometers and output the
distance expressed in miles. 1 km = 0.62137 mile. Use constant declaration.
18. A class has four exams in one term. Write a program that will read in a stud
ent's four exam scores as integer and output the student's average.
19. Write a program that reads in 10 integer values, entered one per line and ou
tputs the average of the 10 integers. Use only one variable for your input. This