Ques:-26) An electric power distribution company charges its domestic consumers as follows:

Computation Units                         Rate of Charge

0-200                                                     Rs. 0.50 per unit

201-400                                                Rs. 100 plus Rs. 0.65 per unit excess of 200

401-600                                                Rs. 230 plus Rs. 0.80 per unit excess of 400

601 and above                                   Rs. 390 plus Rs. 1.00 per unit excess of 600

The program reads the customer number and power consumed and prints the amount to be paid by the customer.

Below is a C program that reads the customer number and power consumed, then calculates and prints the amount to be paid by the customer based on the given rate structure.

				
					#include"stdio.h"
#include"conio.h"
void main()
{
  int c_no,po,r;
  float total=0,t=0;
  clrscr();
  printf("enter the customer number:");
  scanf("%d",&c_no);
  printf("enter the power consumed by consumer:");
  scanf("%d",&po);
  if(po>0&&po<=200)
     total=po*0.50;
  else if(po>200&&po<=400)
  {
     r=po-200;
     t=r*0.65;
     total=(200*0.50)+t+100;
  }
  else if(po>400&&po<=600)
  {
    r=po-400;
    t=r*0.80;
    total=(200*0.50)+(200*0.65)+t+230;
  }
  else if(po>600)
  {
     r=po-600;
     t=r*1;
     total=(200*0.50)+(200*0.65)+(200*0.80)+t+390;
  }
  else
    printf("wrong data inserted:");
  printf("\ncostomer no---power consumed---total amount\n");
  printf("    %d            %d            %f",c_no,po,total);
  getch();
}

				
			

Out Put

Another Example

				
					#include <stdio.h>

int main() {
    int customerNumber;
    int unitsConsumed;
    float amount = 0.0;

    // Requesting input from the user
    printf("Enter customer number: ");
    scanf("%d", &customerNumber);
    printf("Enter units consumed: ");
    scanf("%d", &unitsConsumed);

    // Compute the amount based on the rate structure
    if (unitsConsumed <= 200) {
        amount = unitsConsumed * 0.50;
    } else if (unitsConsumed <= 400) {
        amount = 100 + (unitsConsumed - 200) * 0.65;
    } else if (unitsConsumed <= 600) {
        amount = 230 + (unitsConsumed - 400) * 0.80;
    } else {
        amount = 390 + (unitsConsumed - 600) * 1.00;
    }

    // Output the results
    printf("Customer Number: %d\n", customerNumber);
    printf("Units Consumed: %d\n", unitsConsumed);
    printf("Amount to be paid: Rs. %.2f\n", amount);

    return 0;
}

				
			

Explanation:

  1. Variable Declaration:

    • customerNumber: stores the customer number.
    • unitsConsumed: stores the number of units consumed.
    • amount: stores the calculated amount to be paid.
  2. Input Request:

    • The program requests the customer number and units consumed from the user.
  3. Computation:

    • The program calculates the amount based on the given rate structure using a series of if-else statements:
      • If units consumed are less than or equal to 200, the charge is unitsConsumed * 0.50.
      • If units consumed are between 201 and 400, the charge is 100 + (unitsConsumed - 200) * 0.65.
      • If units consumed are between 401 and 600, the charge is 230 + (unitsConsumed - 400) * 0.80.
      • If units consumed are above 600, the charge is 390 + (unitsConsumed - 600) * 1.00.
  4. Output Results:

    • The program prints the customer number, units consumed, and the amount to be paid.

Output:

Here is an example output of the program for different inputs:

  1. Example 1:

				
					Enter customer number: 101
Enter units consumed: 150
Customer Number: 101
Units Consumed: 150
Amount to be paid: Rs. 75.00

				
			

Example 2:

				
					Enter customer number: 102
Enter units consumed: 350
Customer Number: 102
Units Consumed: 350
Amount to be paid: Rs. 197.50

				
			

Example 3:

				
					Enter customer number: 103
Enter units consumed: 500
Customer Number: 103
Units Consumed: 500
Amount to be paid: Rs. 310.00


				
			

Example 4:

				
					Enter customer number: 104
Enter units consumed: 750
Customer Number: 104
Units Consumed: 750
Amount to be paid: Rs. 540.00



				
			

To compile and run this program, you can use a C compiler like gcc:

				
					gcc program.c -o program
./program




				
			

Replace program.c with the filename of your C program.

Scroll to Top