Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
13 views4 pages

Programs

The document contains a series of C++ programs that perform various mathematical operations based on user input. These include calculating the sum, product, and average of five numbers; finding the area of a triangle, circumference, and circle; converting temperatures between Fahrenheit and Celsius; swapping numbers; and calculating the square and cube of a number. Each program is structured with input prompts, calculations, and output statements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views4 pages

Programs

The document contains a series of C++ programs that perform various mathematical operations based on user input. These include calculating the sum, product, and average of five numbers; finding the area of a triangle, circumference, and circle; converting temperatures between Fahrenheit and Celsius; swapping numbers; and calculating the square and cube of a number. Each program is structured with input prompts, calculations, and output statements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

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();
}

You might also like