Javatpoint Logo
Javatpoint Logo

Electricity bill program in C

In this article, we will create a program to calculate an electricity bill in C.


The output of the program will show the bill amount in rupees:

Example 1:
Enter the number of units consumed: 150
Electricity Bill Amount: Rs. 1125.00
Example 2:
Enter the number of units consumed: 50
Electricity Bill Amount: Rs. 375.00
Example 3:
Enter the number of units consumed: 0
Electricity Bill Amount: Rs. 0.00


In this program, we define the unit and tax rates as constants using the #define directive. The calculate bill function takes the number of units consumed as an argument and calculates the bill amount by multiplying the units with the unit rate. It also calculates the tax amount based on the tax rate and adds it to the bill amount.

In the main Function, we prompt the user to enter the number of units consumed using printf and scanf. After that, we call the calculateBill Function to calculate the total bill amount. Finally, we display the bill amount using printf.

Please note that it is a basic and plain example, and it does not include input validation or additional features like customer information or bill payment options. You can enhance the program according to your requirements.

Algorithm of the above program:

Here's the algorithm of the electricity bill program:

  1. Start the program.
  2. Define the constant UNIT_RATE for the rate per unit consumed and TAX_RATE for the tax rate.
  3. Define the function calculateBill that takes the number of units consumed as an argument and returns the bill amount.
    • Declare variables billAmount and taxAmount.
    • Calculate the bill amount by multiplying the units consumed by UNIT_RATE.
    • Calculate the tax amount by multiplying the bill amount by TAX_RATE.
    • Add the tax amount to the bill amount.
    • Return the bill amount.
  4. Define the main FunctionFunction.
    • Declare variables units and totalBill.
    • Prompt the user to input the number of units consumed.
    • Read the input and store it in the units variable.
    • Call the calculateBill FunctionFunction, passing the units variable as an argument, and store the returned value in totalBill.
    • Display the bill amount by printing "Electricity Bill Amount: $totalBill".
  5. End the program.

This algorithm outlines the steps taken in the program to calculate and display the electricity bill amount based on the user input.

Bill Calculation:

To calculate the bill based on the given inputs and predefined rates, you can use the following formula:


billAmount is the total bill amount (including tax).

units is the number of units consumed by the user.

UNIT_RATE is the predefined rate per unit consumed.

Next TopicRSA algorithm in C

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA