1) Write a program that reads 5 values from the users
and prints its sum, product, and average.
# include <iostream.h>
# include <conio.h>
void main()
{
int a,b,c,d,e,sum,prod;
float avg;
clrscr();
cout<<"Enter 1st number: ";
cin>>a;
cout<<"Enter 2nd number: ";
cin>>b;
cout<<"Enter 3rd number: ";
cin>>c;
cout<<"Enter 4th number: ";
cin>>d;
cout<<"Enter 5th number: ";
cin>>e;
sum=a+b+c+d+e;
prod=a*b*c*d*e;
avg=sum/5.0;
cout<<"Sum: "<<sum<<endl;
cout<<"Product: "<<prod<<endl;
cout<<"Average: "<<avg<<endl;
getch();
}
2) Write a program that read height and width from the users and
find the area of triangle. (Area = length x width)
# include <iostream.h>
# include <conio.h>
void main()
{
float width, height, area;
clrscr();
cout<<"Enter width: ";
cin>>width;
cout<<"Enter height: ";
cin>>height;
area= width * height;
cout<<"Area of triangle: "<<area<<endl;
getch();
}
3) Write a program that reads the radius from the users and find
area of circumference (A = 2(Pi)r)
# include <iostream.h>
# include <conio.h>
void main()
{
float r, area;
clrscr();
cout<<"Enter radius: ";
cin>>r;
area= 2*(22/7)*r;
cout<<"Area of Circumference: "<<area<<endl;
getch();
}
4) Write a program that reads intial velocity, acceleration and
time from the user and find its final velocity.
(vf = vi + at)
# include <iostream.h>
# include <conio.h>
void main()
{
int t;
float vi, a, vf;
clrscr();
cout<<"Enter Initial Velocity: ";
cin>>vi;
cout<<"Enter Acceleration: ";
cin>>a;
cout<<"Enter time span: ";
cin>>t;
vf = vi + a*t;
cout<<"Final Velocity: "<<vf<<endl;
getch();
}
5) Write a program that read two numbers and swap them.
(e.g. a=5; b=6; output: a =6; b=5;)
# include <iostream.h>
# include <conio.h>
void main()
{
int a, b, c;
clrscr();
cout<<"Enter value of A: ";
cin>>a;
cout<<"Enter value of B: ";
cin>>b;
cout<<"Value of "A" before swap: "<<a<<endl;
cout<<"Value of "B" before swap: "<<b<<endl;
c = a;
a = b;
b = c;
cout<<"Value of "A" after swap: "<<a<<endl;
cout<<"Value of "B" after swap: "<<b<<endl;
getch();
}
6) Write a program that read two numbers and swap them without
using 3rd variable.
# include <iostream.h>
# include <conio.h>
void main()
{
int a, b;
clrscr();
cout<<"Enter value of A: ";
cin>>a;
cout<<"Enter value of B: ";
cin>>b;
cout<<"Value of "A" before swap: "<<a<<endl;
cout<<"Value of "B" before swap: "<<b<<endl;
a = a + b;
b = a - b;
a = a - b;
cout<<"Value of "A" after swap: "<<a<<endl;
cout<<"Value of "B" after swap: "<<b<<endl;
getch();
}
7) Write a program that read temperature in Fehrenheit and convert
it into celsius.
( c = 5/9*(f-32))
# include <iostream.h>
# include <conio.h>
void main()
{
float f, c;
clrscr();
cout<<"Enter Temperature in Fahrenheit: ";
cin>>f;
c = ((0.55)*(f-32));
cout<<"Temperature in Celsius: "<<c<<endl;
getch();
}
8) Write a program that read temperature in Celsius and convert it
into Fahrenheit.
( c = 9/5*(c+32))
# include <iostream.h>
# include <conio.h>
void main()
{
float f, c;
clrscr();
cout<<"Enter Temperature in Celsius: ";
cin>>c;
f = ((1.8)*(c + 32));
cout<<"Temperature in Fahrenheit: "<<f<<endl;
getch();
}
9) Write a program that read a number from the user and find its
square and cube.
(square = a*a; cube = a*a*a;)
# include <iostream.h>
# include <conio.h>
void main()
{
int n, s, c;
clrscr();
cout<<"Enter Number: ";
cin>>n;
s = n * n;
c = n * n * n;
cout<<"Square: "<<s<<endl;
cout<<"Cube: "<<c<<endl;
getch();
}
10) Write a program that read a radius and find area of circle. (A
= pi*r*r)
# include <iostream.h>
# include <conio.h>
void main()
{
float r, area;
clrscr();
cout<<"Enter Radius: ";
cin>>r;
area= ((3.14) * r *r);
cout<<"Area of Circle: "<<area<<endl;
getch();
}