By 25/02/2014 6 Comments

Program Example # 03 For Arithmetic Operators in C++

Problem Statement:

Write a program that takes radius of a circle from the user and calculates the diameter, circumference and area of the circle and display the result.

Solution (Code Snippet):

#include <iostream.h>
main ()
{
// declare variables
float radius, diameter, circumference, area;
// prompt the user for radius of a circle
cout << "Please enter the radius of the circle " ;
cin >> radius ;
// calculate the diameter, circumference and area of the circle
// implementing formula i.e. diameter = 2 r circumference = 2 ח r and area = ח r2
diameter = radius * 2 ;
circumference = 2 * 3.14 * radius ; // 3.14 is the value of ח (Pi)
area = 3.14 * radius * radius ;
// display the results
cout << "The diameter of the circle is : " << diameter ;
cout << "The circumference of the circle is : " << circumference ;
cout << "The area of the circle is : " << area ;
}

Output:

A sample output of the above program is given below.

Please enter the radius of the circle 5

The diameter of the circle is : 10

The circumference of the circle is : 31.4

The area of the circle is : 78.5







Posted in: C++ Basics

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .