You are on page 1of 51

Central Calcutta Polytechnic

Name: Arnab Das


Roll: 10005501
Subject: C Programming
Assignment no: 1 & 2
Dept: Computer Science & Technology

Academic Session: 2020-2021


Page |2

INDEX
** For direct jump to the program clik on “Program Title’s”
Sl. Program Title Page No. Teacher
No. Sign.
Assignment: 1
1. Write a C program to perform input/output of all 5
basic data types.
2. Write a C program to enter two number and find 6
their sum.
3. Write a C program to enter two number and 7
perform all arithmetic operations.
4. Write a C program to enter length and breadth 8
of a rectangle and find its perimeter.
5. Write a C program to enter length and breadth 9
of a rectangle and find its area.
6. Write a C program to enter radius of a circle and 10
find its diameter, circumference and area.
7. Write a C program to enter length in centimeter 11
and convert it into meter and kilometer.
8. Write a C program to enter temperature in 12
Celsius and convert it into Fahrenheit.
9. Write a C program to enter temperature in 13
Fahrenheit and convert to Celsius.
10. Write a C program to convert days into years, 14
weeks and days.
11. Write a C program to find power of any number 15
x ^ y.
12. Write a C program to enter any number and 16
calculate its square root.
13. Write a C program to enter two angles of a 17
triangle and find the third angle.
14. Write a C program to enter base and height of a 18
triangle and find its area.
15. Write a C program to calculate area of an 19
equilateral triangle.
16. Write a C program to enter marks of five 20
subjects and calculate total, average and
percentage.
17. Write a C program to enter P, T, R and calculate 21
Simple Interest.
18. Write a C program to enter P, T, R and calculate 22
Compound Interest.
Assignment: 2

Arnab Das | 10005501

C Programing
Page |3

19 Write a C program to find maximum between 23


two numbers.
20 Write a C program to find maximum between 24
three numbers.
21 Write a C program to check whether a number is 25
negative, positive or zero.
22 Write a C program to check whether a number is 26
divisible by 5 and 11 or not.
23 Write a C program to check whether a number is 27
even or odd.
24 Write a C program to check whether a year is 28
leap year or not.
25 Write a C program to check whether a character 29
is alphabet or not.
26 Write a C program to input any alphabet and 30
check whether it is vowel or consonant.
27 Write a C program to input any character and 31
check whether it is alphabet, digit or special
character.
28 Write a C program to check whether a character 32
is uppercase or lowercase alphabet.
29 Write a C program to input week number and 33
print week day.
30 Write a C program to input month number and 35
print number of days in that month.
31 Write a C program to count total number of 37
notes in given amount.
32 Write a C program to input angles of a triangle 39
and check whether triangle is valid or not.
33 Write a C program to input all sides of a triangle 40
and check whether triangle is valid or not.
34 Write a C program to check whether the triangle 41
is equilateral, isosceles or scalene triangle.
35 Write a C program to find all roots of a 42
quadratic equation.
36 Write a C program to calculate profit or loss. 44
37 Write a C program to input marks of five 45
subjects Physics, Chemistry, Biology,
Mathematics and Computer. Calculate
percentage and grade according to following:
Percentage >= 90% : Grade A
Percentage >= 80% : Grade B
Percentage >= 70% : Grade C
Percentage >= 60% : Grade D
Percentage >= 40% : Grade E
Percentage < 40% : Grade F
38 Write a C program to input basic salary of an 47
employee and calculate its Gross salary

Arnab Das | 10005501

C Programing
Page |4

according to following:
Basic Salary <= 10000 : HRA = 20%, DA =
80%
Basic Salary <= 20000 : HRA = 25%, DA =
90%
Basic Salary > 20000 : HRA = 30%, DA = 95%
39 Write a C program to input electricity unit 48
charges and calculate 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.

Q1: Write a C program to perform input/output of all


basic data types.
Program Code:
//Write a C programe to preform input/output of all basic data types.

Arnab Das | 10005501

C Programing
Page |5

#include<stdio.h>
main()
{
int a;
float b;
char c;
printf("Enter an Integer: ");
scanf("%d",&a);
printf("Enter a Float: ");
scanf("%f",&b);
printf("Enter a Charector: ");
fflush(stdin);
scanf("%c",&c);
printf("Integer: %d,\nFloat: %.2f,\nCharector: %c",a,b,c);
}

Output:

Q2: Write a C program to enter two number and find


their sum.
Program Code:
//Write a C program to enter two number and find their sum.
#include<stdio.h>

Arnab Das | 10005501

C Programing
Page |6

main()
{
int a;
float b,s;
printf("Enter 1st number: ");
scanf("%d",&a);
printf("Enter 2nd number: ");
scanf("%f",&b);
s=a+b;
printf("The sum of %d and %.2f is %.2f",a,b,s);
}

Output:

Q3: Write a C program to enter two number and


perform all arithmetic operations.
Program Code:
//Write a C program to enter two number and perform all arithmetic operations.
#include<stdio.h>

Arnab Das | 10005501

C Programing
Page |7

main()
{
int a,b,A,S,M,D;
printf("Enter 1st number: ");
scanf("%d",&a);
printf("Enter 2nd number: ");
scanf("%d",&b);
A=a+b;//Addition
S=a-b;//Subtraction
M=a*b;//Multiplication
D=a/b;//Division
printf("Addition is: %d\nSubtraction: is %d\nMultiplication is: %d\nDivision
is: %d",A,S,M,D);
}

Output:

Q4: Write a C program to enter length and breadth of a


rectangle and find its perimeter.
Program Code:
// Write a C program to enter length and breadth of a rectangle and find its perimeter.
#include<stdio.h>
main()

Arnab Das | 10005501

C Programing
Page |8

{
int l,b,p;
printf("Enter length of the rectangle: ");
scanf("%d",&l);//Length
printf("Enter breadth of the rectangle: ");
scanf("%d",&b);//Breadth
p=2*(l+b);//Perimeter
printf("The Perimeter is: %d",p);
}

Output:

Q5: Write a C program to enter length and breadth of a


rectangle and find its area.
Program Code:
//Write a C program to enter length and breadth of a rectangle and find its area.
#include<stdio.h>
main()
{
int l,b,a;

Arnab Das | 10005501

C Programing
Page |9

printf("Enter length of the rectangle: ");


scanf("%d",&l);//Length
printf("Enter breadth of the rectangle: ");
scanf("%d",&b);//Breadth
a=(l*b);//Area
printf("The area is: %d",a);
}

Output:

Q6: Write a C program to enter radius of a circle and


find its diameter, circumference and area.
Program Code:
//Write a C program to enter radius of a circle and find its diameter, circumference and
area.
#include<stdio.h>
main()
{
int r,d;

Arnab Das | 10005501

C Programing
P a g e | 10

float c,a;
printf("Enter Radius of a circle: ");
scanf("%d",&r);//Radius
d=2*r;//Diameter
c=2*3.14*r;//Circumference
a=3.14*r*r;//Area
printf("Diameter is: %d\nCircumference is: %.2f\nArea is :%.2f",d,c,a);
}

Output:

Q7: Write a C program to enter length in centimeter and


convert it into meter and kilometer.
Program Code:
//Write a C program to enter length in centimeter and convert it into meter and
kilometer.
#include<stdio.h>
main()
{
float l,m,km;

Arnab Das | 10005501

C Programing
P a g e | 11

printf("Enter Length in Centimeter: ");


scanf("%f",&l);//Lenghth
m=l/100;//Meter
km=l/100000;//kilometer
printf("Meter is: %.2f\nKilometer is :%.5f",m,km);
}

Output:

Q8: Write a C program to enter temperature in Celsius


and convert it into Fahrenheit.
Program Code:
//Write a C program to enter temperature in Celsius and convert it into Fahrenheit.
#include<stdio.h>
main()
{
float c,f;

Arnab Das | 10005501

C Programing
P a g e | 12

printf("Enter a Temperature in Celsius: ");


scanf("%f",&c);//Celsius
f=(9*c+160)/5;
printf("Equivallent Tempareture in Fahrenheitr :%.2f",f);
}

Output:

Q9: Write a C program to enter temperature in


Fahrenheit and convert to Celsius.
Program Code:
//Write a C program to enter temperature in Fahrenheit and convert to Celsius.
#include<stdio.h>
main()
{
float c,f;
printf("Enter a Temperature in Fahrenheit: ");

Arnab Das | 10005501

C Programing
P a g e | 13

scanf("%f",&f);//Fahrenheit
c=(5*f-160)/9;//Celsius
printf("Equivallent Tempareture in Celsius is: %.2f",c);
}

Output:

Q10: Write a C program to convert days into years,


weeks and days.
Program Code:
//Write a C program to convert days into years, weeks and days.
#include<stdio.h>
main()
{
int d,y,w;
printf("Enter days: ");
scanf("%d",&d);//Days

Arnab Das | 10005501

C Programing
P a g e | 14

y=d/365;//Year
d=d%365;
w=d/7;//Week
4645
d=d%7;
printf("%d Years, %d Weeks, %d Days",y,w,d);
}

Output:

Q11: Write a C program to find power of any number x


^ y.
Program Code:
//Write a C program to find power of any number x ^ y.
#include<stdio.h>
#include<math.h>
main()
{
int a,b,p;
printf("Enter Two numbers: ");

Arnab Das | 10005501

C Programing
P a g e | 15

scanf("%d%d",&a,&b);//Days
p=pow(a,b);
printf("%d to the power %d is: %d",a,b,p);
}

Output:

Q12: Write a C program to enter any number and


calculate its square root.
Program Code:
//Write a C program to enter any number and calculate its square root.
#include<stdio.h>
#include<math.h>
main()
{
float n,s;
printf("Enter a Number: ");
scanf("%f",&n);//Number

Arnab Das | 10005501

C Programing
P a g e | 16

s=sqrt(n);//Square Root
printf("The Square Root is : %f",s);
}

Output:

Q13: Write a C program to enter two angles of a


triangle and find the third angle.
Program Code:
//Write a C program to enter two angles of a triangle and find the third angle.
#include<stdio.h>
main()
{
float a,b,c;
printf("Enter First Angle: ");
scanf("%f",&a);
printf("Enter Second Angle: ");
scanf("%f",&b);

Arnab Das | 10005501

C Programing
P a g e | 17

c=180-(a+b);
printf("If the angles are %.2f and %.2f then third angle is: %.2f",a,b,c);
}

Output:

Q14: Write a C program to enter base and height of a


triangle and find its area.
Program Code:
//Write a C program to enter base and height of a triangle and find its area.
#include<stdio.h>
main()
{
float b,l,a;
printf("Enter Base: ");
scanf("%f",&b);//Base
printf("Enter Length: ");
scanf("%f",&l);//Length

Arnab Das | 10005501

C Programing
P a g e | 18

a=0.5*(b*l);//Area
printf("If the base is %.3f and the length is %.3f Then Area is: %.3f",b,l,a);
}

Output:

Q15: Write a C program to calculate area of an


equilateral triangle.
Program Code:
//Write a C program to calculate area of an equilateral triangle.
#include<stdio.h>
main()
{
float s,a;
printf("Enter a Side: ");
scanf("%f",&s);//Side of an Equilateral Triangle
a=(1.732/4)*(s*s);
printf("If a Side is %.3f Then the Area of an Equilateral Triangle is: %.3f",s,a);
}

Arnab Das | 10005501

C Programing
P a g e | 19

Output:

Q16: Write a C program to enter marks of five subjects


and calculate total, average and percentage.
Program Code:
//Write a C program to enter marks of five subjects and calculate total, average and
percentage.
#include<stdio.h>
main()
{
int s1,s2,s3,s4,s5,t;
float a,p;
printf("Enter marks of five subjects: ");
scanf("%d%d%d%d%d",&s1,&s2,&s3,&s4,&s5);//Subjects
t=s1+s2+s3+s4+s5;//Total
a=(float)t/5;//Average

Arnab Das | 10005501

C Programing
P a g e | 20

p=((100*t)/500);//Percentage
printf("Total is: %d\nAverage is: %.2f\nPercentage is: %.2f",t,a,p);
}

Output:

Q17: Write a C program to enter P,T,R and calculate


Simple Interest.
Program Code:
//Write a C program to enter P,T,R and calculate Simple Interest.
#include<stdio.h>
main()
{
int P,T;
float R,I;
printf("Enter Principal:");
scanf("%d",&P);//Principal
printf("Enter Time:");
scanf("%d",&T);//Time
printf("Enter Rate of Interest: ");
scanf("%f",&R);//Rate of interest

Arnab Das | 10005501

C Programing
P a g e | 21

I=(P*T*R)/100;//Simple Interest
printf("Interest of %d and %d and %.2f is %.2f",P,T,R,I);
}

Output:

Q18: Write a C program to enter P,T,R and calculate


Compound Interest.
Program Code:
//Write a C program to enter P,T,R and calculate Compound Interest.
#include<stdio.h>
#include<math.h>
main()
{
int P,n,T,b;
float A,R,a,c;
printf("Enter Principal:");
scanf("%d",&P);//Principal
printf("Enter Rate of Interest: ");
scanf("%f",&R);//Rate of interest
printf("Enter Time Period:");
scanf("%d",&n);//Time Period
printf("Enter Time in year:");

Arnab Das | 10005501

C Programing
P a g e | 22

scanf("%d",&T);//Time
a=1+(R/n);
b=n*T;
c=pow(a,b);
A=P*c;//Compound Interest
printf("Compound Interest of %d, %.2f, %d and %d is: %.2f",P,R,n,T,A);
}

Output:

Q19: Write a C program to find maximum between two


numbers.
Program Code:
//Write a C program to find maximum between two numbers.
#include<stdio.h>
main()
{
int a,b;
printf("Enter two numbers: ");
scanf("%d%d",&a,&b);
if (a>b)
printf("Max is: %d",a);
else
printf("Max is: %d",b);
}

Arnab Das | 10005501

C Programing
P a g e | 23

Output:

Q20: Write a C program to find maximum between


three numbers.
Program Code:
//Write a C program to find maximum between three numbers.
#include<stdio.h>
main()
{
int a,b,c;
printf("Enter 3 numbers: ");
scanf("%d%d%d",&a,&b,&c);
if(a>b && a>c)
printf("Max is: %d",a);
else if(b>a && b>c)
printf("Max is: %d",b);
else

Arnab Das | 10005501

C Programing
P a g e | 24

printf("Max is: %d",c);


}

Output:

Q21: Write a C program to check whether a number is


negative, positive or zero.
Program Code:
//Write a C program to check whether a number is negative, positive or zero.
#include<stdio.h>
main()
{
int a;
printf("Enter a number: ");
scanf("%d",&a);
if (a<0)
printf("Negative");
else if (a>0)
printf("Positive");

Arnab Das | 10005501

C Programing
P a g e | 25

else
printf("zero");
}

Output:

Q22: Write a C program to check whether a number is


divisible by 5 and 11 or not.
Program Code:
//Write a C program to check whether a number is divisible by 5 and 11 or not.
#include<stdio.h>
main()
{
int a;
printf("Enter a number: ");
scanf("%d",&a);

if(a%5==0 && a%11==0)


printf("Divisible");

Arnab Das | 10005501

C Programing
P a g e | 26

else
printf("Non-Divisible");
}

Output:

Q23: Write a C program to check whether a number is


even or odd.
Program Code:
//Write a C program to check whether a number is even or odd.
#include<stdio.h>
main()
{
int a;
printf("Enter a Number:");
scanf("%d",&a);
if ((a%2)==0)
printf("Even Number");
else if ((a%2)==1)

Arnab Das | 10005501

C Programing
P a g e | 27

printf("Odd Number");
}

Output:

Q24: Write a C program to check whether a year is leap


year or not.
Program Code:
//Write a C program to check whether a year is leap year or not.
#include<stdio.h>
main()
{
int y;
printf("Enter a year: ");
scanf("%d",&y);
if((y%100!=0 && y%4==0)||(y%400==0))
printf("leap year");
else
printf("Not a leap year");

Arnab Das | 10005501

C Programing
P a g e | 28

Output:

Q25: Write a C program to check whether a character is


alphabet or not.
Program Code:
//Write a C program to check whether a character is alphabet or not.
#include<stdio.h>
main()
{
char A1;
printf("Enter a Character: ");
scanf("%c",&A1);
if ((A1>=65 && A1<=90) || (A1>=97 && A1<=122))
printf("Alphabet");
else
printf("not an Alphabet");

Arnab Das | 10005501

C Programing
P a g e | 29

Output:

Q26: Write a C program to input any alphabet and


check whether it is vowel or consonant.
Program Code:
//Write a C program to input any alphabet and check whether it is vowel or consonant.

#include<stdio.h>

main()

char A1;

printf("Enter a Alphabet: ");

scanf("%c",&A1);

switch(A1)

case 'A':

case 'a':

case 'E':

case 'e':

Arnab Das | 10005501

C Programing
P a g e | 30

case 'I':

case 'i':

case 'O':

case 'o':

case 'U':

case 'u':

printf("Vowel");

break;

default:

printf("Consonant");

Output:

Q27: Write a C program to input any character and


check whether it is alphabet, digit or special character.
Program Code:
//Write a C program to input any character and check whether it is alphabet, digit or
special character.
#include<stdio.h>
main()
{
char A1;
printf("Enter a Character: ");
scanf("%c",&A1);
if ((A1>=65 && A1<=90) || (A1>=97 && A1<=122))
printf("Alphabet");
else if(A1>=48 && A1<=57)

Arnab Das | 10005501

C Programing
P a g e | 31

printf("Digit");
else
printf("Special character");
}

Output:

Q28: Write a C program to check whether a character is


uppercase or lowercase alphabet.
Program Code:
//Write a C program to check whether a character is uppercase or lowercase alphabet.
#include<stdio.h>
main()
{
char A1;
printf("Enter a Character: ");
scanf("%c",&A1);
if ((A1>=65 && A1<=90) || (A1>=97 && A1<=122))
{
if (A1>=65 && A1<=90)
printf("Uppar Case");

Arnab Das | 10005501

C Programing
P a g e | 32

else if(A1>=97 && A1<=122)


printf("Lower Case");
}
else
printf("Not An Alphabet");
}

Output:

Q29: Write a C program to input week number and


print week day.
Program Code:
//Write a C program to input week number and print week day.
#include<stdio.h>
main()
{
int A;
printf("Enter a Week number: ");
scanf("%d",&A);
switch(A)
{
case 1:
printf("Sunday");
break;

Arnab Das | 10005501

C Programing
P a g e | 33

case 2:
printf("Monday");
break;
case 3:
printf("Tuesday");
break;
case 4:
printf("Wednesday");
break;
case 5:
printf("Thursday");
break;
case 6:
printf("Friday");
break;
case 7:
printf("Saturday");
break;
default:
printf("Not a Week Number");
}
}

Output:

Arnab Das | 10005501

C Programing
P a g e | 34

Arnab Das | 10005501

C Programing
P a g e | 35

Q30: Write a C program to input month number and


print number of days in that month.
Program Code:
//Write a C program to input month number and print number of days in that month.
#include<stdio.h>
main()
{
int A;
printf("Enter a Month Number: ");
scanf("%d",&A);
switch(A)
{
case 1:
printf("Days in that month: 31");
break;
case 2:
printf("Days in that month: 29");
break;
case 3:
printf("Days in that month: 31");
break;
case 4:
printf("Days in that month: 30");
break;
case 5:
printf("Days in that month: 31");
break;
case 6:
printf("Days in that month: 30");
break;

Arnab Das | 10005501

C Programing
P a g e | 36

case 7:
printf("Days in that month: 31");
break;
case 8:
printf("Days in that month: 31");
break;
case 9:
printf("Days in that month: 30");
break;
case 10:
printf("Days in that month: 31");
break;
case 11:
printf("Days in that month: 30");
break;
case 12:
printf("Days in that month: 31");
break;
default:
printf("Not a Month Number");
}
}

Output:

Arnab Das | 10005501

C Programing
P a g e | 37

Q31: Write a C program to count total number of notes


in given amount.
Program Code:
//Write a C program to count total number of notes in given amount.
#include<stdio.h>
main()
{
int A,B,C,D,E,F,G,H,I,J,N;
printf("Enter Amount: ");
scanf("%d",&J);//Total
A=J/2000;//A=2000
J=J%2000;
B=J/500;//B=500
J=J%500;
C=J/200;//C=200
J=J%200;
D=J/100;//D=100
J=J%100;
E=J/50;//E=50
J=J%50;
F=J/20;//F=20
J=J%20;
G=J/10;//G=10
J=J%10;
H=J/5;//H=5
J=J%5;
I=J/2;//I=2

Arnab Das | 10005501

C Programing
P a g e | 38

J=J%2;//J=1
N=A+B+C+D+E+F+G+H+I+J;
printf("2000: %d, \n500: %d, \n200: %d, \n100: %d, \n50: %d, \n20:
%d, \n10: %d, \n5: %d, \n2: %d, \n1: %d",A,B,C,D,E,F,G,H,I,J);
printf("\nTotal Notes: %d",N);
}

Output:

Arnab Das | 10005501

C Programing
P a g e | 39

Q32: Write a C program to input angles of a triangle


and check whether triangle is valid or not.
Program Code:
//Write a C program to input angles of a triangle and check whether triangle is valid or
not.
#include<stdio.h>
main()
{
int A1,A2,A3,S;
printf("Enter Angles: ");
scanf("%d%d%d",&A1,&A2,&A3);
S=A1+A2+A3;
if (S==180 && A1>0 && A2>0 && A3>0)
printf("Valid Triangle");
else
printf("Not a Valid Triangle");
}

Output:

Arnab Das | 10005501

C Programing
P a g e | 40

Arnab Das | 10005501

C Programing
P a g e | 41

Q33: Write a C program to input all sides of a triangle


and check whether triangle is valid or not.
Program Code:
//Write a C program to input all sides of a triangle and check whether triangle is valid
or not.
#include<stdio.h>
main()
{
float S1,S2,S3;
printf("Enter Sides: ");
scanf("%f%f%f",&S1,&S2,&S3);
if ((S1+S2)>S3 || (S2+S3)>S1 || (S3+S1)>S2)
printf("Valid Triangle");
else
printf("Not a Valid Triangle");
}

Output:

Arnab Das | 10005501

C Programing
P a g e | 42

Q34: Write a C program to check whether the triangle is


equilateral, isosceles or scalene triangle.
Program Code:
//Write a C program to check whether the triangle is equilateral, isosceles or scalene triangle.
#include<stdio.h>
main()
{
float S1,S2,S3;
printf("Enter Sides: ");
scanf("%f%f%f",&S1,&S2,&S3);
if (S1==S2 && S2==S3)
printf("Equilateral Triangle");
else if (S1==S2 || S2==S3 || S3==S1)
printf("Isosceles Triangle");
else
printf("Scalene Triangle");
}

Output:

Arnab Das | 10005501

C Programing
P a g e | 43

Q35: Write a C program to find all roots of a quadratic


equation.
Program Code:
//Write a C program to find all roots of a quadratic equation.
#include<stdio.h>
#include<math.h>
main()
{
float a,b,c,d,x1,x2;
printf("Input the value of a: ");
scanf("%f",&a);
printf("Input the value of b: ");
scanf("%f",&b);
printf("Input the value of c: ");
scanf("%f",&c);
d=b*b-4*a*c;//Discriminant
if(d==0)
{
printf("Both roots are equal");
x1=-b/(2.0*a);
x2=x1;
printf("\nFirst Root x1= %f",x1);
printf("\nSecond Root x2= %f",x2);
}
else if(d>0)
{
printf("Both roots are real and diff");
x1=(-b+sqrt(d))/(2*a);

Arnab Das | 10005501

C Programing
P a g e | 44

x2=(-b-sqrt(d))/(2*a);
printf("\nFirst Root x1= %f",x1);
printf("\nSecond Root x2= %f",x2);
}
else
printf("No Solution.");
}

Output:

Arnab Das | 10005501

C Programing
P a g e | 45

Q36: Write a C program to calculate profit or loss.


Program Code:
//Write a C program to calculate profit or loss.
#include<stdio.h>
main()
{
float c,sp;//c=Cost of the Product, sp=Selling price
printf("Enter Cost of the Product: ");
scanf("%f",&c);
printf("Enter Selling price: ");
scanf("%f",&sp);
if (c<sp)
printf("Profit");
else if (c>sp)
printf("Loss");
else
printf("Neither Loss, Nor Profit");
}

Output:

Arnab Das | 10005501

C Programing
P a g e | 46

Arnab Das | 10005501

C Programing
P a g e | 47

Q37: Write a C program to input marks of five subjects Physics,


Chemistry, Biology, Mathematics and Computer. Calculate
percentage and grade according to following:
Percentage >= 90% : Grade A
Percentage >= 80% : Grade B
Percentage >= 70% : Grade C
Percentage >= 60% : Grade D
Percentage >= 40% : Grade E
Percentage < 40% : Grade F
Program Code:
#include<stdio.h>

main()

float phy,chem,bio,math,com,sum,per;

printf("Enter Marks of Physics: ");

scanf("%f",&phy);

printf("Enter Marks of Chemistry: ");

scanf("%f",&chem);

printf("Enter Marks of Biology: ");

scanf("%f",&bio);

printf("Enter Marks of Mathematics: ");

scanf("%f",&math);

printf("Enter Marks of Computer: ");

scanf("%f",&com);

sum=phy+chem+bio+math+com;

per=(100*sum)/500;

if (per >= 90)

printf("Grade A");

else if (per >= 80)

printf("Grade B");

else if (per >= 70)

Arnab Das | 10005501

C Programing
P a g e | 48

printf("Grade C");

else if (per >= 60)

printf("Grade D");

else if (per >= 40)

printf("Grade E");

else if (per < 40)

printf("Grade F");

Output:

Arnab Das | 10005501

C Programing
P a g e | 49

Q38: Write a C program to input basic salary of an


employee and calculate its Gross salary according to
following:
Basic Salary <= 10000 : HRA = 20%, DA = 80%
Basic Salary <= 20000 : HRA = 25%, DA = 90%
Basic Salary > 20000 : HRA = 30%, DA = 95%
Program Code:
#include<stdio.h>

main()

float S;

printf("Enter Salary: ");

scanf("%f",&S);

if (S <= 10000)

S=(S+(S*0.2)+(S*0.8));

else if (S <= 20000)

S=(S+(S*0.25)+(S*0.9));

else if (S > 20000)

S=(S+(S*0.3)+(S*0.95));

printf("Gross Salary: %.2f",S);

Output:

Arnab Das | 10005501

C Programing
P a g e | 50

Arnab Das | 10005501

C Programing
P a g e | 51

Q39: Write a C program to input electricity unit charges and


calculate 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.
Program Code:
#include<stdio.h>

main()

float U,P;

printf("Enter Electricity unit: ");

scanf("%f",&U);

if (U <= 50)

P=U*0.50;

else if (U <= 100)

P=50*0.50+(U-50)*0.75;

else if (U <= 200)

P=50*0.50+100*0.75+(U-150)*1.20;

else if (U > 200)

P=50*0.50+100*0.75+100*1.20+(U-250)*1.50;

P=P+P*0.2;

printf("Total electricity bill is: %.2f",P);

Output:

Arnab Das | 10005501

C Programing

You might also like