Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

ECE 175: Computer Programming for Engineering Applications

Lab 1

Topics: Basic C and Branch structure

Demo to TA or ULA your code for each problem by the end of your lab session in order to earn your lab 1 score.

Problem 1 (15 points): Write a C program that accepts three integers, find the maximum and find new numbers by subtracting between the maximum and each integer.

Sample code execution 1: bold entered by a user Enter three integers: 130 50 100

Maximum is 130

New numbers are 0 80 30

Sample code execution 2: bold entered by a user Enter three integers: 30 175 255

Maximum is 255

New numbers are 225 80 0

More test cases:

If the inputs are 255, 255, 255, then the maximum is 255 and the new numbers are 0, 0, 0

If the inputs are 100, 190, 65, then the maximum is 190 and the new numbers are 90, 0, 125

Problem 2 (15 points): A water supply company charges the water consumption, as follows:

- Fixed amount of $10

- For the first 30 cubic meters (m3), $0.6/m3

- For the next 20 cubic meters (m3), $0.8/m3

- For every additional cubic meter (m3) r, $1.0/m3

Write a C program that reads the water consumption in cubic meters (m3) and displays the cost. For example, if a user enters

- 15.7, the cost is 10 + 0.6*15.7 = 19.42 dollars.

- 45.25, the cost is 10 + 0.6*(30) + 0.8*(45.25-30) = 40.20 dollars.

- 85.5, the cost is 10 + 0.6*(30) + 0.8*(20) + 1*(85.5-50) = 79.50 dollars.

Sample code executions: bold entered by a user Enter water consumption in cubic meter (m^3): -1

the value canNOT be negative

Enter water consumption in cubic meter (m^3): 15.7

cost is 19.42 dollars

Enter water consumption in cubic meter (m^3): 45.25

cost is 40.20 dollars

Enter water consumption in cubic meter (m^3): 85.5

cost is 79.50 dollars

Enter water consumption in cubic meter (m^3): 30

cost is 28.00 dollars

Enter water consumption in cubic meter (m^3): 50

cost is 44.00 dollars