0% found this document useful (0 votes)
11 views3 pages

Assignment 3 (A)

Uploaded by

rr3284544
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

Assignment 3 (A)

Uploaded by

rr3284544
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

6.

Write a program in C to build a simple calculator


supporting Addition, Subtraction, Multiplication and Division.

CODE:-
#include
<stdio.h> int
main()
{
/*Name-Ananya
Hazra Purpose-
calculator Date-
4/10/24*/
float
a,b,result; int
o;
printf ("enter the numbers and
operation"); scanf ("%f %d %f",
&a,&o,&b);
if (o==1)
{
result=a+b;
}
else if(o==2)
{
result=a-b;
}
else if(o==3)
{
result=a*b;
}
else if(o==4)
{
result=a/b;
}
printf ("result=%f", result);
return 0;
}

OUTPUT:-
enter the numbers and operation8 2 8
result=0.000000

7. Write a program in C to compute the monthly electricity bill.


User provides “total no of units consumed” as an int input.
The rate chart is as follows:
i)For first 50 Units: Rs 5/- per unit
ii)For next 100 Units: Rs 6/- per
unit iii)For next 200 Units: Rs 7/-
per unit iv)Beyond that: Rs 8/-
per unit
CODE:-
#include
<stdio.h> int
main()
{
/*
Name-Ananya
Hazra Purpose-Bill
calculator Date-
4/10/24*/
int unit, bill;
printf ("enter the current
unit="); scanf ("%d", &unit);
if (unit<=50)
{
bill=unit*5;
}
else if (unit>50 && unit<=150)
{
bill=(unit-50)*6+50*5;
}
else if (unit>150 && unit<=350)
{
bill=(unit-150)*7+100*6+50*5;
}
else if (unit>350)
{
bill=(unit-350)*8+200*7+100*6+50*5;
}
printf ("bill=%d",
bill); return 0;
}

OUTPUT:-
enter the current unit=400
bill=2650

You might also like