Lab Assignment 1
Lab Assignment 1
Course-BTech(CSE)
Roll No.-24155589
#include<stdio.h>
void main() INPUT:
{ Enter 1st number=12
int x,y,z; Enter 2nd number=17
printf("enter the first number");
scanf("%d",&x);
printf("enter the second number");
scanf("%d",&y); OUTPUT:
z=x+y; Sum of x and y is 29
printf("Sum of x and y is z %d",z);
}
Question 2)WAP to find Fahrenheit for a given centigrade temperature.
#include<stdio.h>
void main() INPUT:
{ Enter the temperature in
float f,c; Celsius:25
printf("ENTER THE TEMPERATURE IN CELCIUS");
scanf("%f",&c);
f=(1.8*c)+32; OUTPUT:
printf("The temperature in farhenheit is %0.2f ",f); The temperature in fahrenheit
} is 77
Question 3)WAP to calculate area of a circle while taking radius as user input.
#include<stdio.h>
#include<math.h>
int main() INPUT:
{ Enter the radius of the circle:11
float r,a;
printf("Enter the radius of the circle");
scanf("%f",&r);
a=3.14*r*r;
OUTPUT:
printf("The area of the circle is %0.2f",a);
The area of the circle is 380.7
return 0;
}
Question 4)WAP to calculate area of a triangle who’s base and height are user input.
#include<stdio.h>
void main()
{ INPUT:
float h,b,a; Enter the height of the triangle:12
printf("Enter the height of the triangle"); Enter the base of the triangle:10
scanf("%f",&h);
printf("Enter the base of the triangle");
scanf("%f",&b);
a=0.5*b*h; OUTPUT:
printf("The area of the triangle is,%f", a); The area of the triangle is 60
}
Question 5)Write a C program to perform swapping of two integers using a third variable.
#include<stdio.h>
void main()
{ INPUT:
int a,b; Enter the value of a:20
printf("Enter the value of a: "); Enter the value of b:40
scanf(" %d",&a);
printf(“Enter the value of b:”);
scanf(“%d”,&b);
a=a+b;
b=a-b; OUTPUT:
a=a-b; The values after swapping are
printf("The Values After Swapping a=40,b=20
Are : \na = %d, b = %d\n",a,b); }