"The best way to cheer yourself up is to try to cheer somebody else up." Mark Twain

Saturday, February 20, 2010

Write a complete C++ program that uses a function called carea() to calculate area of a circle. The function carea() receives radius of float type and returns area of double type. The function main() gets a radius value from the user, calls carea(), and displays the result. The function carea() is local to main.


#include<iostream.h>
#include<conio.h>


void main()
{
double carea(float r)
{
double ar = (double) ( 3.14 * r * r );
return ar;
}


float rad;


cout<<  " \n Enter Radius :";
cin >>rad;


double area = carea(rad);


cout<<"\n The area of the circle of radius " << rad << " unit is " << area << "sq. unit ";


getch();


}

No comments:

Post a Comment

C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.
Now Playing: Ballade Pour Adeline

About Me

My photo
I m an IT lecturer of a college. I love social-work. I want to do something beneficial for society before dying , that can promote our society, to some extent.