The output of the program will be as following.

 

 

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:

In this problem we take the input (radius of a circle) from the user. So that we can use cin statement to prompt the user to enter the radius of a circle. We store this radius in a variable. We also need other variables to store diameter, circumference and area of the circle. To obtain the correct result, we declare these variables of type float, instead of int data type, as we know that the int data type stores the whole numbers only. Here in our problem the area or circumference of the circle can be in decimal values. After getting the radius we use the formulae to find the diameter, circumference and area of the circle and then display these results on the screen.

 

 

 

Previous

 

 

TOC

 

 

Next