Write a Program That Calculates The Area Of A Circle & Accepts Radius From The User

Posted in

Write a Program That Calculates The Area Of A Circle & Accepts Radius From The User
vinaykhatri

Vinay Khatri
Last updated on November 21, 2024

    In this post, we have explained a program that calculates the area of a circle and accepts the radius from the user with C+ and Python. So let us get started.

    Problem Statement

    We need to write a program in C, C++, and Python that accepts the radius of the circle from the user and calculates its area. To Calculate the area of a circle we can use the following formula area of the circle (A)= ?r2 A = area of a circle ? = pi which value is 3.14 r = radius of the circle.

    C Program that Calculates the Area of a Circle and accepts radius from the user

    #include <stdio.h>
    
    int main()
    {	
    	float A, r;
    	
    	//input the circle radius
    	printf("Enter the radius of the circle in cm: ");
    	
    	scanf("%f", &r);
    	
    	//area of the circle 
    	A= 3.14*r*r;
    	printf("The area of the circle is: %.2f cmsq", A);
    	return 0;
    }

    Output

    Enter the radius of the circle in cm: 3
    The area of the circle is: 28.26 cmsq

    C++ Program that Calculates the Area of a Circle and accepts radius from the user

    #include<iostream.h>
    #include< conio.h>
    #include<math.h>
    void main()
    {
    clrscr();
    float A,r;
    cout<<"Enter the radius of the circle in cm: ";
    cin>>r;
    A = 3.14*pow(r,2);
    cout<<"The area of the circle is: "<<A <<" cmsq";
    getch();
    }

    Output:

    Enter the radius of the circle in cm: 3
    The area of the circle is: 28.26 cmsq

    Python Program that Calculates the Area of a Circle

    r = float(input("Enter the radius of the circle in cm: "))
    A = 3.14*(r*r)
    print("The area of the circle is:",A,"cmsq")

    Output:

    Enter the radius of the circle in cm: 3
    The area of the circle is: 28.26 cmsq

    Wrapping Up!

    In this programming tutorial, we learned how to implement a Circle Area calculator in C, C++, and Python. The program is very simple and straightforward all it does, ask the radius value from the user and calculate the area of the circle based on the entered radius in cm sq.

    People are also reading:

    Leave a Comment on this Post

    0 Comments