This is a program that uses constant argument in the function. The program given below uses pi as a constant argument. The program is extendable. Go enjoy the program. Lets begin…..
Program to find the area of circle using function with constant argument
float cir(float,float pi=3.142);
//clear the screen.
//declare variable as float.
//Input the radius.
cout<<“Enter the radius”<<endl;
//calculate area using function.
cout<<“Area of circle is “<<area;
float cir(float r,float pi)
Enter the radius.
Area of circle is 3.142
How does it work
- You enter the radius.
- The function calculates the area.
- The area is printed.
The program can be extended as this is a basic of c++ and this concept can be used in any function that requires a constant argument like here pi is constant i.e value of pi does not change. For ex. you can make a program of simple interest where rate is constant. Go extent it…..
- Include ‘iostream.h’ and ‘conio.h’ files.
- Declare the function prototype with a constant argument
- Add void main.
- Start program by first clearing the screen.
- Declare the variables as float (name them as you want.)
- Add the cout and cin of necessary inputs.
- Add the cout of area and call the function.
- Add the function definition outside the void main().
At the end
You learnt creating the C++ program of Area of different circle using function with constant argument pi. So now enjoy the program.
Please comment on the post and share it.
And like it if you liked.