C program to calculate electricity bill
Write a C program to enter electricity unit charges and calculate the total electricity bill according to the given condition:
For first 50 units Rs. 0.50/unit
For next 100 units Rs. 0.75/unit
For next 100 units Rs. 1.20/unit
For unit above 250 Rs. 1.50/unit
An additional surcharge of 20% is added to the bill
How to calculate electricity bill using if else in C programming. Program to find electricity bill using if else in C.
#include <stdio.h>
int main()
{
int unit;
float amt, total_amt, sur_charge;
/*
* Reads unit charges from user
*/
printf("Enter total consumed units: ");
scanf("%d", &unit);
/*
* Calculates electricity bill according to given conditions
*/
if(unit <= 50)
{
amt = unit * 0.50;
}
else if(unit <= 150)
{
amt = 25 + ((unit-50)*0.75);
}
else if(unit <= 250)
{
amt = 100 + ((unit-150)*1.20);
}
else if(unit > 250)
{
amt = 220 + ((unit-250)*1.50);
}
/*
* Calculates total electricity bill
* after adding sur charges
*/
sur_charge = amt*0.20;
total_amt = amt+sur_charge;
printf("\nElectricity Bill = Rs. %.2f", total_amt);
return 0;
}
Electricity Bill = Rs. 125.00
Write a C program to enter electricity unit charges and calculate the total electricity bill according to the given condition:
For first 50 units Rs. 0.50/unit
For next 100 units Rs. 0.75/unit
For next 100 units Rs. 1.20/unit
For unit above 250 Rs. 1.50/unit
An additional surcharge of 20% is added to the bill
How to calculate electricity bill using if else in C programming. Program to find electricity bill using if else in C.
/*C program to calculate electricity bill*//* C program to calculate total electricity bill*/
#include <stdio.h>
int main()
{
int unit;
float amt, total_amt, sur_charge;
/*
* Reads unit charges from user
*/
printf("Enter total consumed units: ");
scanf("%d", &unit);
/*
* Calculates electricity bill according to given conditions
*/
if(unit <= 50)
{
amt = unit * 0.50;
}
else if(unit <= 150)
{
amt = 25 + ((unit-50)*0.75);
}
else if(unit <= 250)
{
amt = 100 + ((unit-150)*1.20);
}
else if(unit > 250)
{
amt = 220 + ((unit-250)*1.50);
}
/*
* Calculates total electricity bill
* after adding sur charges
*/
sur_charge = amt*0.20;
total_amt = amt+sur_charge;
printf("\nElectricity Bill = Rs. %.2f", total_amt);
return 0;
}
output
Enter total consumed units: 150Electricity Bill = Rs. 125.00
Disgusting
ReplyDelete