Given an equation of the circle X2 + Y2 = R2 whose center at origin (0, 0) and the radius is R. The task is to find area of circle.
Examples :
Input : X*X + Y*Y = 25 Output : The area of circle centered at origin is : 78.55 Input : X*X + Y*Y = 64 Output : The area of circle centered at origin is : 201.088
Approach
- Given an equation X2 + Y2 = R2 and store it into string ‘str’.
- Count length of string and store it into ‘len’.
- Start loop from 0 to len – 1 and check if str[i] == ‘=’.
- Store characters after ‘=’ into string variable st.
- Convert string ‘st’ into digits and store it into ‘radius_square’.
- Use formula Pi * R2 to find area of circle(multiply by Pi).
C++
// C++ program to find area of circle // when equation of circle give. #include <bits/stdc++.h> #define PI 3.142 using namespace std; // Function to find the area double findArea(double radius) { return PI * pow(radius, 2); } // Function to return the value of radius static double findradius(string str) { // Initialization double radius = 0; // For storing the value of R*R string st = ""; // For counting the number of // spaces in the string int c = 0; // calculate the length of the int len = str.length(); // getting the value of R*R // After = sign for (int i = 0; i < len; i++) { if (str[i] == '=') { c = 1; } else if (c == 1 && str[i] != ' ') { st = st + str[i]; } } // Converting the digits into integer // Taking square root of that number radius = (double)sqrt(stoi(st)); return radius; } int main() { // Static input for equation // of circle string str = "X*X + Y*Y = 100"; // calling the Function double radius = findradius(str); // Display the result cout << "The area of circle " << "centered at origin is : " << findArea(radius) << endl; return 0; } |
chevron_right
filter_none
Java
// Java program to find area of circle // when equation of circle give. import java.io.*; public class GFG { static double PI = 3.142; // Function to find the area static double findArea(double radius) { return PI * Math.pow(radius, 2); } // Function to return the value of radius static double findradius(String str) { double radius = 0; // For storing the value of radius * radius String st = ""; // For counting the number of spaces // in the string int c = 0; // calculate the length of the int len = str.length(); // getting the value of radius * radius // After = sign for (int i = 0; i < len; i++) { if (str.charAt(i) == '=') { c = 1; } else if (c == 1 && str.charAt(i) != ' ') { st = st + str.charAt(i); } } // Converting the digits into integer // Taking square root of that number if (c == 1) radius = (double)Math.sqrt( Integer.parseInt(st)); return radius; } public static void main(String[] args) { // Static input for equation of circle String str = "X*X + Y*Y = 100"; // calling the Function double radius = findradius(str); // Display the result System.out.println("The area of circle" + " centered at origin is : " + findArea(radius)); } } |
chevron_right
filter_none
Python3
# python program to find area of circle # when equation of circle give. import math # Function to find the area def findArea(radius): return math.pi * pow(radius, 2) # Function to return the value of radius def findradius(str): #Initialization radius = 0 # For storing the value of R*R st = "" # For counting the number of # spaces in the string c = 0 # calculate the length of the Len = len(str) # getting the value of R*R # After = sign for i in range(0, Len): if (str[i] == '='): c = 1 elif (c == 1 and str[i] != ' '): st = st + str[i] # Converting the digits into integer # Taking square root of that number radius = float(math.sqrt(float(st))) return radius # Static input for equation # of circle str = "X*X + Y*Y = 100" # calling the Function radius = findradius(str) # Display the result print( "The area of circle " , "centered at origin is : " , (findArea(radius))) # This code is contributed by Sam007. |
chevron_right
filter_none
C#
// C# program to find area of circle // when equation of circle give. using System; class GFG { // Function to find the area static double findArea(double radius) { return Math.PI * Math.Pow(radius, 2); } // Function to return the value of radius static double findradius(string str) { double radius = 0; // For storing the value // of radius * radius String st = ""; // For counting the number // of spaces in the string int c = 0; // calculate the length of the int len = str.Length; // getting the value of radius * radius // After = sign for (int i = 0; i < len; i++) { if (str[i] == '=') { c = 1; } else if (c == 1 && str[i] != ' ') { st = st + str[i]; } } // Converting the digits into integer // Taking square root of that number if (c == 1) radius = (double)Math.Sqrt( int.Parse(st)); return radius; } // Driver code public static void Main() { // Static input for equation of circle string str = "X*X + Y*Y = 100"; // calling the Function double radius = findradius(str); // Display the result Console.WriteLine("The area of circle" + " centered at origin is : " + System.Math.Round(findArea(radius),1)); } } // This code is contributed by Sam007 |
chevron_right
filter_none
Output:
The area of circle centered at origin is : 314.2
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- Find area of the larger circle when radius of the smaller circle and difference in the area is given
- Equation of circle when three points on the circle are given
- Program to calculate area of inner circle which passes through center of outer circle and touches its circumference
- Area of the circle that has a square and a circle inscribed in it
- Equation of circle from centre and radius
- Angle subtended by the chord to center of the circle when the angle subtended by the another equal chord of a congruent circle is given
- Program to find area of a circle
- Find the area of largest circle inscribed in ellipse
- Check if a circle lies inside another circle or not
- Area of a Circumscribed Circle of a Square
- Area of square Circumscribed by Circle
- Program to calculate area of an Circle inscribed in a Square
- Area of circle inscribed within rhombus
- Area of a circle inscribed in a regular hexagon
- Area of a square inscribed in a circle which is inscribed in an equilateral triangle
- Area of circle which is inscribed in equilateral triangle
- Area of decagon inscribed within the circle
- Area of largest Circle inscribe in N-sided Regular polygon
- Area of largest Circle that can be inscribed in a SemiCircle
- Area of Equilateral triangle inscribed in a Circle of radius R
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

