Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C program to generate an electricity bill
Based on the units consumed by the user, the electricity bill is generated. If number of units consumed are more then, the rate of a unit charge will also increase.
The logic applied if minimum units are consumed by the user is as follows −
if (units < 50){
amt = units * 3.50;
unitcharg = 25;
}
The logic applied if units are in between 50 to 100 is given below −
else if (units <= 100){
amt = 130 + ((units - 50 ) * 4.25);
unitcharg = 35;
}
The logic applied if units are in between 100 to 200 is as stated below −
else if (units <= 200){
amt = 130 + 162.50 + ((units - 100 ) * 5.26);
unitcharg = 45;
}
The logic applied if number of units are more than 200 is mentioned below −
amt = 130 + 162.50 + 526 + ((units - 200 ) * 7.75); unitcharg = 55;
Therefore, the final amount will be generated with the logic as given below −
total= amt+ unitcharg;
Example
Following is the C Program to generate an electricity bill −
#include <stdio.h>
int main(){
int units;
float amt, unitcharg, total;
printf(" Enter no of units consumed : ");
scanf("%d", &units);
if (units < 50){
amt = units * 3.50;
unitcharg = 25;
}else if (units <= 100){
amt = 130 + ((units - 50 ) * 4.25);
unitcharg = 35;
}else if (units <= 200){
amt = 130 + 162.50 + ((units - 100 ) * 5.26);
unitcharg = 45;
}else{
amt = 130 + 162.50 + 526 + ((units - 200 ) * 7.75);
unitcharg = 55;
}
total= amt+ unitcharg;
printf("electricity bill = %.2f", total);
return 0;
}
Output
When the above program is executed, it produces the following result −
Enter no of units consumed: 280 electricity bill = 1493.50
Advertisements