about-text

SoftOSet is the most remarkable programming site. SoftOSet provides the fresh conceptual and professional programs, articles, books, and other interesting and technical writings. SoftOSet is the most reliable programming site to learn the programs and the basics of the popular programming languages. SoftOSet is the hub of the informative and research based articles.

Area of Circle Program in C++ and C




Area of Circle is A=Ï€r2 and to solve the mathematical problems is the part time job of C++. In this article we will deal with the area of circle calculation program in both C++ and C language. We will develop a program in which user will enter the radius of his given circle and the program will print him area using the formula A=Ï€r2 .

Programmer will declare a variable “A” to store area of circle, use 3.14 in place of Ï€ and r2 by r*r. so the original statement will be like that.

A=3.14*(r*r);



Area of Circle Program in C++


First we are developing the C++ program to find the area the code for this program is as under.

 

Code

//date 27 january 2019

//program to find area of circle using function call by value

#include<iostream>

using namespace std;

int area(int);

int main()

{

            int radius;

            cout<<"Enter the radius to Find Area \n";

            cin>>radius;

            cout<<"Area ="<<area(radius);

return 0;

}

int area(int r)

{

            int a;

            a=3.14*r*r;

            return a;

}

 

Output


Here is the sample output of this program. Calculate area of the circle from radius.

 

 

 

Area of Circle Program in C


This is the version C of the above program. This version will perform the same task as performed above with C++ language but this program will use C language.

 

Code


//date 27 january 2019

//program to find area of circle using function call by value

#include<stdio.h>

int area(int);

int main()

{

            int radius;

            printf("Enter the radius to Find Area \n");

            scanf("%d",&radius);

printf("Area =%d",area(radius));

return 0;

}

int area(int r)

{

            int a;

            a=3.14*r*r;

            return a;

}

 

 

Output


Here also the same output is coming of this program. Calculating area from radius same like previous C++ language program.

 

 

 

Conclusion


Finally, we concluded that tasks which are performed in the C++ language can be performed in C language in some cases but not at all. Because C++ in some context such as objects and classes is more advanced than C language.

 

Thank You and I hope you will easily understand this simple code but if not don’t worry. Contact us we will assist you by our best.


Post a Comment

Feel Free to Comment Us

Previous Post Next Post

Recents