ICT - C Programming - Chapter 5 (25 Questions Solved)
ICT - C Programming - Chapter 5 (25 Questions Solved)
C Programming
Question-1: Write a C program for the average calculation of three numbers.
Answer:
#include<stdio.h>
#include<conio.h>
int main()
{
float a,b,c,avg;
scanf("%f%f%f",&a,&b,&c);
avg=(a+b+c)/3;
printf("Average=%f",avg);
return 0;
}
Question-2:The land and the height of the triangle are given.Write a C program for
determining the area of the triangle.
Answer:
#include<stdio.h>
#include<conio.h>
int main()
{
float b,h,area;
scanf("%f%f",&b,&h);
area=b*h;
printf("Area=%f",area);
return 0;
}
Question-3:Circle of radius is given.Write a C program for determining the area of the
Circle.
Answer:
#include<stdio.h>
#include<conio.h>
int main()
{
float r,area;
scanf("%f",&r);
area=3.1416*r*r;
printf("Area=%f",area);
return 0;
}
Sajib Saha
North South University(Dept. of ECE)
Page |2
Question-4:The three sides of the triangle are given in length.Write a C program for
determining the area of the triangle.
Answer:
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
float a,b,c,s,area;
scanf("%f%f%f",&a,&b,&c);
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("Area of Triangle=%f",area);
return 0;
}
Question-5:Write a C program for converting Celsius Temperature to Fahrenheit
Temperature.
Answer:
#include<stdio.h>
#include<conio.h>
int main()
{
float c,f;
scanf("%f",&c);
f=9*c/5+32;
printf("Farenheit Temperature=%f",f);
return 0;
}
Question-6:Write a C program for converting Farenheit Temperature to Celsius
Temperature.
Answer:
#include<stdio.h>
#include<conio.h>
int main()
{
float f,c;
scanf("%f",&f);
c=(f-32)*5/9;
printf("CelsiusTemperature=%f",c);
return 0;
}
Sajib Saha
North South University(Dept. of ECE)
Page |3
Question-7:The length and the width of the Rectangular are given.Write a C program for
determining the area of the Rectangular.
Answer:
#include<stdio.h>
#include<conio.h>
int main()
{
float l,w,area;
scanf("%f%f",&l,&w);
area=l*w;
printf("Area of Rectangular=%f",area);
return 0;
}
Question-8: Write a C program for determining whether a number is positive or negative.
Answer:
#include<stdio.h>
#include<conio.h>
int main()
{
float n;
scanf("%f",&n);
if(n<0)
printf("Negetive Number=%f",n);
else
printf("Positivetive Number=%f",n);
return 0;
}
Question-9: Write a C program for determining the large number in three numbers.
Answer:
#include<stdio.h>
#include<conio.h>
int main()
{
float a,b,c;
scanf("%f%f%f",&a,&b,&c);
if((a>b)&&(a>c))
printf("Maximum Number=%f",a);
else if((b>a)&&(b>c))
printf("Maximum Number=%f",b);
else
printf("Maximum Number=%f",c);
return 0;
}
Sajib Saha
North South University(Dept. of ECE)
Page |4
Question-10: Write a C program for determining the leap year or not leap year.
Answer:
#include<stdio.h>
#include<conio.h>
int main()
{
int y;
scanf("%d",&y);
if((y%400==0)//(y%4==0)&&(y%100!=0))
printf("Leap year=%d",y);
else
printf("Not Leap year=%d",y);
return 0;
}
Question-11:Write a C program for determining the even number or odd number.
Answer:
#include<stdio.h>
#include<conio.h>
int main()
{
int n;
scanf("%d",&n);
if(n%2==0)
printf("The Even Number=%d",n);
else
printf("The Odd Number=%d",n);
return 0;
}
Question-12:Write a C program for determining the pass mark or fail mark.
Answer:
#include<stdio.h>
#include<conio.h>
int main()
{
int m;
scanf("%d",&m);
if(m<40)
printf("The Fail Mark=%d",m);
else
printf("The Pass Mark=%d",m);
return 0;
}
Sajib Saha
North South University(Dept. of ECE)
Page |5
Question-23:Write a program to find the average of five numbers.Take all the numbers from user
as input.
Sample output-1: Sample output-2:
Enter 5 numbers:4 8 2 1 5 Enter 5 numbers:4.1 8.2 2 1.3 5.5
Average is:4.00 Average is:4.22
Answer:
For Sample output-1:
#include<stdio.h>
#include<math.h>
int main()
{
int a,b,c,d,e,avg;
scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
avg=(a+b+c+d+e)/5;
printf("Average of 5 numbers=%d",avg);
return 0;
}
For Sample output-2:
#include<stdio.h>
#include<math.h>
int main()
{
float a,b,c,d,e,avg;
scanf("%f%f%f%f%f",&a,&b,&c,&d,&e);
avg=(a+b+c+d+e)/5;
printf("Average of 5 numbers=%f",avg);
return 0;
}
Question -24:Write a program to calculate the area & the perimeter of a circle.Take radius as input.
Sample output:
Enter Enter the radius:5
Area Area of the circle:78.5
Answer:
#include<stdio.h>
#include<math.h>
int main()
{
float r,p,area;
printf("Enter the radius:");
scanf("%f",&r);
p=2*r;
printf("The perimeter of Circle=%f",p);
area=3.1416*r*r;
printf("The area of Circle=%f",area);
return 0;
}
Sajib Saha
North South university(Dept. of ECE)
Page |9
Question-25:Write a program that finds the height and area of a right triangle (900) using
Pythagorean theorem.Take hypotenuse and base as input from the user.Use pow() and sqrt()
function.
Sample output:
Enter base:3
Enter hypotenuse:5
Height is:4.00
Area is:6.00
Answer:
#include<stdio.h>
#include<math.h>
int main()
{
float b,h,height,area;
printf("Enter the base:");
scanf("%f",&b);
printf("Enter the hypotenuse:");
scanf("%f",&h);
height=sqrt(h*h-b*b);
printf("Height of Triangle=%f",height);
area=0.5*b*height;
printf("The Area of triangle=%f",area);
return 0;
}
Sajib Saha
North South University(Dept. of ECE)