In this tutorial you will learn about the C program to Calculate Electricity Bill and its application with practical example.
C program to Calculate Electricity Bill
In this tutorial, we will learn to create a C program that will calculate the Electricity Bill in C programming.
Prerequisites
Before starting this tutorial, we assume that you are best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C Programming.
- Arithmetic Operators in C Programming.
What is an Electricity Bill?
The electricity bill is the generated net payable amount charged by the electricity-providing company. The electricity bill is generated on the basis of the consumption of the electricity in units by the consumer.
Algorithm:-
1 2 3 4 5 6 7 8 9 10 11 |
1. Declaring the required variable for the program. 2. Taking the input number of units from the user. 3. Passing that units to program code in conditional statements. 4. Calculating the electricity bill. 5. Printing the Bill of electricity. 6. End The Program. |
Program Description.
In this program, First will take the input units from the user. Secondly, we will use the conditional statements to generate the electricity bill of the user. At last, we will print the electricity bill of the user.
With the help of the below program, we can calculate the electricity bill.
Program Code:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
/* C program to Calculate Electricity Bill */ #include<stdio.h> int main() { //Declaring the required variables for the program. float bill, units; //bill = it will hold the float value for the result bill. //units = it will hold the input number of units from the user. //Taking the input number of units from the user printf("Enter the units consumed= "); //Scanning the input number of units from the user. scanf("%f",&units); //Calculating the electricity bill. if(units<=50 && units>=0) { bill=units*3.50; //Printing the electricity bill. printf("Electricity Bill=%f Rupees",bill); } else if(units<=100 && units>50) { bill=50*3.50+(units-50)*4; printf("Electricity Bill=%f Rupees",bill); } else if(units<=250 && units>150) { bill=50*3.50+100*4+(units-150)*5.20; printf("Electricity Bill=%f Rupees",bill); } else if(units>250) { bill=50*3.50+100*4+100*5.20+(units-250)*6.50; printf("Electricity Bill=%f Rupees",bill); } else { printf("Please enter valid consumed units..."); } return 0; } |
Output:-
In the above program, we have first initialized the required variable.
![](https://www.w3adda.com/wp-content/uploads/2022/01/1-40.jpg)
- bill = it will hold the float value for the bill
- units = it will hold the input float value for the units.
Taking the input units from the user.
![](https://www.w3adda.com/wp-content/uploads/2022/01/2-41.jpg)
Calculating the Bill of the user.
![](https://www.w3adda.com/wp-content/uploads/2022/01/3-37.jpg)
Printing the output bill.