Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
34 views

ICT - C Programming - Chapter 5 (25 Questions Solved)

Uploaded by

sajib.sahaeee18
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

ICT - C Programming - Chapter 5 (25 Questions Solved)

Uploaded by

sajib.sahaeee18
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Page |1

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-13:Write a C program for successively calculating sum of 1+2+3+…….+n .


Answer:
#include<stdio.h>
#include<conio.h>
int main()
{
int n,i,s=0;
scanf("%d",&n);
for(i=1;i<=n;i=i+1)
{
s=s+i;
}
printf("Summation of Series=%d",s);
return 0;
}
Question-14:Write a C program for successively calculating sum of 2+4+6+…….+n .
Answer:
#include<stdio.h>
#include<conio.h>
int main()
{
int n,i,s=0;
scanf("%d",&n);
for(i=2;i<=n;i=i+2)
{
s=s+i;
}
printf("Summation of Series=%d",s);
return 0;
}
Question-15:Write a C program for successively calculating sum of 1+3+5+…….+n .
Answer:
#include<stdio.h>
#include<conio.h>
int main()
{
int n,i,s=0;
scanf("%d",&n);
for(i=1;i<=n;i=i+2)
{
s=s+i;
}
printf("Summation of Series=%d",s);
return 0;
}
Sajib Saha
North South University(Dept. of ECE)
Page |6

Question-16:Write a C program for successively calculating multiplication of 1x2x3x…….xn.


Answer:
#include<stdio.h>
#include<conio.h>
int main()
{
int n,i,m=1;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
m=m*i;
}
printf("Multiplication of Series=%d",m);
return 0;
}
Question-17: Write a C program for successively calculating multiplication of 1x2x3x…….xn.
Answer:
#include<stdio.h>
#include<conio.h>
int main()
{
int n,i,fact=1;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
fact=fact*i;
}
printf("Factorial Number =%d",fact);
return 0;
}
Question-18:Write a C program for Determining GCD(Greatest Common Divisor) of 2
numbers.
Answer:
#include<stdio.h>
#include<conio.h>
int main()
{
int l,s,t;
scanf("%d%d",&l,&s);
do
{
t=l%s;
l=s;
s=t;
}
printf("Fractorial Number =%d",fact);
return 0; Sajib Saha
} North South University(Dept. of ECE)
Page |7

Question-19:Write a c program to display “Hello Computer” on the screen.


Answer:
#include<stdio.h>
int main()
{
printf("Hello Computer\n");
return 0;
}
Question-20:Write a C program to display Your name,Address & City in different lines.
Answer:
#include<stdio.h>
int main()
{
printf("Sharon Saha\nVill:North Kalihati\nP.O.+P.S.:Kalihati\nDist:Tangail\n");
return 0;
}
Question-21:Print The following chart.Make sure your output matches exactly with the
format.(Hint:Use the \t escape character to align text in each line.)
NUMBER SQUAER CUBE
1 1 1
2 4 8
3 9 27
4 16 64
5 25 125
Answer:
#include<stdio.h>
int main()
{
printf("NUMBER\tSQUARE\tCUBE\n1\t1\t1\n2\t4\t8\n3\t9\t27\n4\t16\t64\n5\t25\t125\n");
return 0;
}
Question-22:Print the following pattern(use the * symble on keyboard).
*
* *
* * *
* * * *
* * * * *
Answer:
#include<stdio.h>
int main()
{
printf("*\n*\t*\n*\t*\t*\n*\t*\t*\t*\n*\t*\t*\t*\t*\n");
return 0; Sajib Saha
} North South University(Dept. of ECE)
Page |8

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)

You might also like