Lab 2 Assignment
Lab 2 Assignment
ID : C-201234
DEPERTMENT OF CSE
CSE-1122
Solution :
#include<stdio.h>
int main()
int a;
float b;
double c;
char d;
return 0;
}
Problem no. 02 : Write a C program to find all the roots of the quadratic
equation .
Solution :
#include <math.h>
#include <stdio.h>
int main() {
discriminant = b * b - 4 * a * c;
if (discriminant > 0) {
else if (discriminant == 0) {
}
else {
realPart = -b / (2 * a);
return 0;
}
Problem no. 04 : Write a C program to convert a temperature reading in
degrees Fahrenheit to degrees Celsius,using the formula C=(5/9)*(F-32) .
Solution :
#include<stdio.h>
int main(){
scanf("%f",&far);
cel=(5/9.0)*(far-32);
return 0;
}
Problem no. 05 : Write a C program to read a length in centimeter scale and
convert it in the inch scale .
Solution :
#include<stdio.h>
int main(){
float centimeter,inch;
scanf("%f",¢imeter);
inch = (centimeter)*(2.54);
return 0;
}
Problem no. 06 : W,X,Y.Z are the marks of a student . Write a C program to
calculate the total and the average of 4 students .
Solution :
#include<stdio.h>
int main(){
int w,x,y,z;
int t1,t2,t3,t4;
float a1,a2,a3,a4;
scanf("%d %d %d %d",&w,&x,&y,&z);
t1=w+x+y+z;
a1=t1/4;
printf("The total marks of 1st student is : %d\n and The average marks is :
%.2f",t1,a1);
scanf("%d %d %d %d",&w,&x,&y,&z);
t2=w+x+y+z;
a2=t2/4;
printf("\nThe total marks of 2nd student is : %d\n and The average marks is :
%.2f",t2,a2);
printf("\n\nEnter the marks for 3rd student : ");
scanf("%d %d %d %d",&w,&x,&y,&z);
t3=w+x+y+z;
a3=t3/4;
printf("\nThe total marks of 3rd student is : %d\n and The average marks is :
%.2f",t3,a3);
scanf("%d %d %d %d",&w,&x,&y,&z);
t4=w+x+y+z;
a4=t4/4;
printf("\nThe total marks of 4th student is : %d\n and The average marks is :
%.2f",t4,a4);
return 0;
}
Problem no. 07 : Write a C program to input month number and print number
of days in that month .
Solution :
#include <stdio.h>
int main()
int month;
scanf("%d", &month);
else
{
printf("\nTHE NUMBER OF DAYS IS 28 . ");
return 0;
}
Problem no. 08: Write a C program to find the hypotenuse of a right triangle
where the other two sides of the triangle are taken as user input .
Solution :
#include<stdio.h>
#include<math.h>
int main(){
int a,b,c;
c=sqrt(pow(a,2)-pow(b,2));
return 0;
}
Problem no. 09 : Write a C program to evaluate the following polynomial
x−1 2 x−1 3 x−1 4
( ) ( ) ( ).
function : y= x−1 + x + x + x
( )
x 2 3 4
Solution :
#include<stdio.h>
#include<math.h>
int main(){
float x,y;
scanf("%f",&x);
y=(x-1)/x+(pow(x-1/x,2))/2+(pow(x-1/x,3))/3+(pow(x-1/x,4))/4;
return 0;
}
Problem no. 10 : Write a C program to calculate the mass of air in a automobile
tire using the formula : PV=0.37(T+460) .
Solution :
#include<stdio.h>
int main(){
int p=32,v=2,t=77;
float m;
m=p*v/(0.37*(77+460));
return 0;
}
Problem no. 11 : Write a C program to calculate the volume and area of a
sphere using the formula’s : V =(4 πr 3)/3 , A=4 π r 2 .
Solution :
#include<stdio.h>
int main(){
float r,volume,area,pi;
pi=3.1416;
scanf("%f",&r);
volume=(4/3)*pi*r*r*r;
area=4*pi*r*r;
return 0;