C Programming LAB Questions with Solutions:
Write a program in C to input 3 numbers and find sum and average.
#include <stdio.h>
void main()
{
int num1, num2, num3, sum,
avg;
printf("Enter three
numbers : ");
scanf("%d%d%d",&num1,
& num2, & num3);
sum=num1+ num2+ num3;
avg=sum/3;
printf("sum = %d ",sum);
printf("average = %d",avg);
}
Write a C program to calculate area and circumference of a circle. (A=3.14xr2 and C= 2x3.14xr)
#include <stdio.h>
void main()
{
float pi,r,a,c;
pi = 3.14;
printf("Enter radius
: ");
scanf("%f",&r);
a=pi*r*r;
c=2*pi*r;
printf("Area = %.2f
\n",a);
printf("Circumference
= %.2f",c);
}
Write a program in C to find square root and cube root of a number. Use sqrt() and cbrt().
#include <stdio.h>
#include <math.h>
void main()
{
float num1, square_root,
cube_root;
printf("Enter a
number : ");
scanf("%f",&num1);
square_root = sqrt(num1);
cube_root=cbrt(num1);
printf("Square root
= %.2f ",square_root);
printf("cube root = %.2f",cube_root);
}
Write a program in C to calculate and print simple interest (SI) and net amount(A), given that SI=PTR/100 and A=SI+P.
#include<stdio.h>
void main ()
{
float p,t,r,si,a;
printf("Enter principal, time and rate : ");
scanf("%f%f%f",&p,&t,&r);
si=p*t*r/100;
a=si+p;
printf(" Simple interest is %.2f \n ",si);
printf(" Net amount is %.2f ",a);
}
Write a program in C to convert temperature from centigrade(c) into Fahrenheit(f). Use f=1.8*c+32
#include<stdio.h>
void main()
{
float c,f;
printf(" Enter
temperature in centigrade ");
scanf("%f",&c);
f=1.8*c+32;
printf(" Temperature
in Fahrenheit = %.2f ",f);
}
Write a program in C to calculate value of s using s=ut+1/2at.
#include<stdio.h>
void main ()
{
float u,t,a,s;
printf("Enter
initial velocity , time and acceleration \n");
scanf("%f%f%f",&u,&t,&a);
s=u*t+0.5*a*t*t;
printf("Distance
covered is %0.2f ",s);
}
Write a program in C to find total surface area of cuboid using (TSA = 2(lb+bh+hl) ).
#include <stdio.h>
void main()
{
float l, b, h, total_surface_area;
printf("Enter the length,
breadth and height of cuboid : ");
scanf("%f%f%f",&l,
&b, &h);
total_surface_area= 2((l*b)+(b*h)+(h*l));
printf("Total Surface
Area = %.2f \n",total_surface_area);
}
Write a program in C to find sum of two distances measured in kilometer and meter. Hint
Kilometer- 234 meter-3532
#include <stdio.h>
void main()
{
int km, m,sum, sum_k, sum_m;
printf("Enter the length in Kilometer: ");
scanf("%d",&km);
printf("Enter the length in meter: ");
scanf("%d",&m);
sum = ((km*1000)+m);
sum_k = sum/1000;
sum_m = sum%1000;
printf("Sum of distance is %d Kilometer and %d meter
\n",sum_k, sum_m);
}
No comments:
Post a Comment