Skip to main content

An electricity board charges the following rates for the use of electricity: for the first 200 units 80 paise per unit: for the next 100 units 90 paise per unit: beyond 300 units Rs 1 per unit. All users are charged a minimum of Rs. 100 as meter charge. If the total amount is more than Rs 400, then an additional surcharge of 15% of total amount is charged. Write a program to read the name of the user, number of units consumed and print out the charges. Program and Algorithm Computer Science Engineering VTU

Electricity sort
#include<stdio.h>

void main()

{

    int units;

    float charges;

    char name[20];

    printf("Enter the name of the customer\n");

    scanf("%s",name);

    printf("Enter the units consumed\n");

    scanf("%d",&units);

    charges=100;

    if(units>0&&units<=200)

    charges=charges+0.8*units;

    else if (units>200&&units<=300)

    charges=charges+0.8*200+(300-units)*0.9;

    else

    charges=charges+0.8*200+100*0.9+(units-300)*1;

    if(charges>400)

    charges=charges+0.15*charges;

    printf("name=%s\n",name);

    printf("units consumed=%d\n",units);

    printf("charges=%f\n",charges);

}
Algorithm: Electricity bill 
Start

Read name, units consumed as units

charge = 100

if units is <= 100 then 

compute charge = charge + units * 0.8 

else If units > 200 and units < 300 then 

compute charge = charge + 200 * 0.8 +(units – 200) * 0.9 

else 

compute charge = charge + (0.15*charge) 

Display name, units, charge

Stop

Comments

Popular posts from this blog

Raju is a Civil Engineer. He is writing software to automate his work. As a part of his requirement, he wants to calculate the circle diameter, circumference, and area. Help Raju to complete his task. Get radius as input.

OUTPUT

Write functions to implement string operations such as compare, concatenate, string length. Convince the parameter passing techniques Program and Algorithm Computer Science Engineering VTU

STRINGconcatenation #include<stdio.h> #include<stdlib.h> int length (char str[]); int compare (char str1[],char str2[]); void concatenate (char str1[],char str2[]); void main() { char str1[30],str2[30]; int choice,a,i,j; printf("enter 1-string comparision\n"); printf("enter 2-string length\n"); printf("enter 3-string concatenation\n"); printf("enter 4-exit\n"); scanf("%d",&choice); switch(choice) { case 1:printf("enter string 1\n"); scanf("%s",str1); printf("enter string 2\n"); scanf("%s",str2); a=compare(str1,str2); if(a==0) { printf("%s and%s are identical\n",str1,str2); } else { printf("%s and%s are not identical\n",str1,str2); } break; ...