Write a C program to calculate an electricity bill
Description: Take the units of electricity used as input and calculate the bill with these rates:
- First 100 units: Rs 5 per unit
- Next 100 units (101 to 200): Rs 7 per unit
- Above 200 units: Rs 10 per unit
C program to calculate the electricity bill
#include <stdio.h>
int main(void) {
int units;
float bill;
printf("Enter units used: ");
scanf("%d", &units);
if (units <= 100) {
bill = units * 5;
} else if (units <= 200) {
bill = 100 * 5 + (units - 100) * 7;
} else {
bill = 100 * 5 + 100 * 7 + (units - 200) * 10;
}
printf("Electricity bill = Rs %.2f\n", bill);
return 0;
}
Output:
Output of the above program is
Enter units used: 250
Electricity bill = Rs 1700.00
How it works
- For 250 units: first 100 units cost 500, the next 100 units cost 700, and the last 50 units cost 500.
- Total is 500 + 700 + 500 = 1700.
Read Else If Ladder.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |