Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

C programming

Laboratory tasks

Lab 3 – Making decisions

1. Write a program to calculate electricity charges for a customer. The program requests
a name, previous meter reading, and current meter reading. The difference in the two
readings gives the number of units of electricity used. The customer pays a fixed
charge of $25 plus 20 cents for each unit used.
Print all the data, the number of units used, and the amount the customer must pay,
appropriately labeled
2. Write a program to calculate the cost of carpeting a rectangular room in a house.
The program must do the following:
Request the length and breadth of the room (assume they are in meters).
Request the cost per square meter of the carpet.
Calculate the area of the room.
Calculate the cost of the carpet for the room.
Print the area and the cost, appropriately labeled.
3. Write a program that requests two weights in kilograms and grams and prints the sum
of the weights. For example, if the weights are 3kg 500g and 4kg 700g, your program
should print 8kg 200g.
4. Write a program that requests two lengths in feet and inches and prints the sum of the
lengths. For example, if the lengths are 5 ft. 4 in. and 8 ft. 11 in., your program should
print 14 ft. 3 in. (1 ft. = 12 in.)
5. You’re selling a product that’s available in two versions: type 1 is a standard version
priced at $3.50, and type 2 is a deluxe version priced at $5.50. Write a program using
only what you’ve learned up to now that prompts for the user to enter the product type
and a quantity, and then calculates and outputs the price for the quantity entered.
6. A variety store gives a 15% discount on sales totaling $300 or more. Write a program
to request the cost of three items and print the amount the customer must pay.
7. Write a program to read two pairs of integers. Each pair represents a fraction. For
example, the pair 3 5 represents the fraction 3/5. Your program should print the sum
of the given fractions. For example, give the pairs 3 5 and 2 3, your program should
print 19/15, since 3/5 + 2/3 = 19/15.
a. Modify the program so that it prints the sum with the fraction reduced to a
proper fraction; for this example, your program should print 1 4/15
8. Write a program to read integer values for month and year and print the number of
days in the month. For example, 4 2005 (April 2005) should print 30, 2
2004(February 2004) should print 29 and 2 1900 (February 1900) should print 28.A
leap year, n, is divisible by 4; however, if n is divisible by 100 then it is a leap year
only if it is also divisible by 400. So, 1900 is not a leap year but 2000 is.
9. Write a program to request two times given in 24-hour clock format and find the time
(in hours and minutes) that has elapsed between the first time and the second time.
You may assume that the second time is later than the first time. Each time is
represented by two numbers: e.g., 16:45 means the time 16:45, that is, 4:45 p.m.
For example, if the two given times are 16:45 and 23:25 your answer should be 6
hours 40 minutes.
a. Modify the program so that it works as follows: if the second time is sooner
than the first time, take it to mean a time for the next day. For example, given
the times 20:30 and 6:15, take this to mean 8.30 p.m. to 6.15 a.m. of the next
day. Your answer should be 9 hours 45 minutes.
10. A bank pays interest based on the amount of money deposited. If the amount is less
than $5,000, the interest is 4% per annum. If the amount is $5,000 or more but less
than $10,000, the interest is 5% per annum. If the amount is $10,000 or more but less
than $20,000, the interest is 6% per annum. If the amount is $20,000 or more, the
interest is 7% per annum.

Write a program to request the amount deposited and print the interest earned for one
year.

11. Write a program to prompt for the name of an item, its previous price, and its current
price. Print the percentage increase or decrease in the price. For example, if the
previous price is $80 and the current price is $100, you should print increase of 25%;
if the previous price is $100 and the current price is $80, you should print decrease of
20%.
12. Suppose you want a program that will take applicant interviews for a large
pharmaceutical corporation. The program should offer interviews to applicants who
meet certain educational specifications. An applicant who meets any of the following
criteria should be accepted for an interview:
Graduates over 25 who studied chemistry and who didn’t graduate from Yale
Graduates from Yale who studied chemistry
Graduates from Harvard who studied economics and aren’t older than 28
Graduates from Yale who are over 25 and who didn’t study chemistry

13. Write a program that will first allow a user to choose one of two options:
Convert a temperature from degrees Celsius to degrees Fahrenheit.
Convert a temperature from degrees Fahrenheit to degrees Celsius.

The program should then prompt for the temperature value to be entered and output
the new value that results from the conversion. To convert from Celsius to Fahrenheit
you can multiply the value by 1.8 and then add 32. To convert from Fahrenheit to
Celsius, you can subtract 32 from the value, then multiply by 5, and divide the result
by 9.

You might also like