0% found this document useful (0 votes)
76 views14 pages

Lab 2 Assignment

This document contains 11 programming problems assigned to the student Jakia Rahman from the Department of Computer Science Engineering. Each problem includes the problem statement and the C code solution. The problems cover topics such as data type sizes, roots of quadratic equations, temperature conversions, and calculating volume and area of spheres.

Uploaded by

Jakia Rahman
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)
76 views14 pages

Lab 2 Assignment

This document contains 11 programming problems assigned to the student Jakia Rahman from the Department of Computer Science Engineering. Each problem includes the problem statement and the C code solution. The problems cover topics such as data type sizes, roots of quadratic equations, temperature conversions, and calculating volume and area of spheres.

Uploaded by

Jakia Rahman
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/ 14

LAB ASSIGNMENT-2

NAME : JAKIA RAHMAN

ID : C-201234

DEPERTMENT OF CSE

CSE-1122

SEMESTER : 1ST (SPRING-2020)


Problem no. 01 : Write a C program to find the size of
int,float,double,char .

Solution :
#include<stdio.h>

int main()

int a;

float b;

double c;

char d;

printf("Enter an integer : %ld bytes\n", sizeof(a));

printf("Enter a float : %ld bytes\n", sizeof(b));

printf("Enter a double : %ld bytes\n", sizeof(c));

printf("Enter a char : %ld bytes\n", sizeof(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() {

double a, b, c, discriminant, root1, root2, realPart, imagPart;

printf("Enter coefficients a, b and c: ");

scanf("%lf %lf %lf", &a, &b, &c);

discriminant = b * b - 4 * a * c;

if (discriminant > 0) {

root1 = (-b + sqrt(discriminant)) / (2 * a);

root2 = (-b - sqrt(discriminant)) / (2 * a);

printf("root1 = %.2lf and root2 = %.2lf", root1, root2);

else if (discriminant == 0) {

root1 = root2 = -b / (2 * a);

printf("root1 = root2 = %.2lf;", root1);

}
else {

realPart = -b / (2 * a);

imagPart = sqrt(-discriminant) / (2 * a);

printf("root1 = %.2lf+%.2lfi and root2 = %.2f-%.2fi", realPart, imagPart,


realPart, imagPart);

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(){

float far , cel;

printf("Enter fahrenheit temperature : ");

scanf("%f",&far);

cel=(5/9.0)*(far-32);

printf("The converted temperature is : %.2f degrees celsius",cel);

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;

printf("Enter centimeter value : ");

scanf("%f",&centimeter);

inch = (centimeter)*(2.54);

printf("The converted length is : %.2f inch",inch);

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;

printf("Enter the marks for 1st student : ");

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);

printf("\n\nEnter the marks for 2nd student : ");

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);

printf("\n\nEnter the marks for 4th student : ");

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;

printf(" Please Enter the Month Number: ");

scanf("%d", &month);

if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 ||


month == 10 || month == 12 )

printf("\nTHE NUMBER OF DAYS IS 31 . ");

else if ( month == 4 || month == 6 || month == 9 || month == 11 )

printf("\nTHE NUMBER OF DAYS IS 30 . ");

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;

printf("Enter The value of a and b\n");

scanf("%d %d", &a,&b);

c=sqrt(pow(a,2)-pow(b,2));

printf("The value of hypotenuse is : %d",c);

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;

printf("Enter the value of x : ");

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;

printf("The result of y is : %.2f",y);

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;

printf("The pressure of the air is 32 psi\n");

printf("The volume of air is 2 cubic square feet\n");

printf("The room temperature is 77 degree fahrenheit\n");

m=p*v/(0.37*(77+460));

printf("The mass of the air is : %.2f" pounds,m);

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;

printf("Enter the value of r : ");

scanf("%f",&r);

volume=(4/3)*pi*r*r*r;

area=4*pi*r*r;

printf("Volume of the sphere is : %.2f\n",volume);

printf("Area of the sphere is : %.2f",area);

return 0;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy