Ad Code

Responsive Advertisement

CALCULATE THE AREA OF A CIRCLE, in all language's code available PYTHON,JAVA,C,CPP

 

CALCULATE THE AREA OF A CIRCLE PYTHON, JAVA, C, CPP

Python code

#Calculate the Area of a Circle:
import math

radius1 = float(input("Enter the radius of the circle: "))
area = math.pi*radius1**2
print("The area of the circle is the :",area)

Output:

Enter the radius of the circle: 5

The area of the circle is : 78.53981633974483


Explanation about the above code clearly explained below:

  • The Python code directly assigns values to lower and upper.
  • The code uses a for loop with the range function to iterate through each number in the given range.
  • The len(str(num)) expression is used to calculate the number of digits in num.
  • The code uses ** for exponentiation.
  • The output is done using the print function. The end parameter ensures numbers are printed with a comma as a separator.

for any question or program or anything asking in the comment box to tell him


Java code

import java.util.Scanner;


public class Main {

    public static void main(String[] args) {

        double radius, area;


        Scanner input = new Scanner(System.in);


        System.out.print("Enter the radius value of the circle: ");

        radius = input.nextDouble();


        area = Math.PI * Math.pow(radius, 2);


        System.out.println("The area of the circle is: " + area);

    }

}

Output:

Enter the radius  value of the circle: 5

The area of the circle is: 78.53981633974483

Explanation about the above code clearly explained below:

  • import java.util.Scanner;: This line imports the Scanner class from the java.util package to read user input.
  • public class Main {: This line is the starting point of the Java program. It declares a public class named "Main".
  • public static void main(String[] args) {: This line declares the main method, which is the entry point of the Java program.
  • double radius, area;: This declares two double variables, radius and area, to store the user input and calculated area respectively.
  • Scanner input = new Scanner(System.in);: This line creates a new instance of the Scanner class to read user input from the console.
  • System.out.print("Enter the radius of the circle: ");: This line prints a message asking the user to enter the radius of the circle.
  • radius = input.nextDouble();: This line reads the user input for the radius and stores it in the radius variable.
  • area = Math.PI * Math.pow(radius, 2);: This line calculates the area of the circle using the Math.PI constant from the Math class and the Math.pow method to calculate the square of the radius.
  • System.out.println("The area of the circle is: " + area);: This line prints the calculated area of the circle.
  • }: This line indicates the end of the main method.
  • }: This line indicates the end of the Main class.

for any question or program or anything asking in the comment box to tell him



C code

#include <stdio.h>

#include <math.h>


int main() {

    float radius, area;


    printf("Enter the radius value of the circle: ");

    scanf("%f", &radius);


    area = M_PI * pow(radius, 2);


    printf("The area of the circle is the: %f\n", area);


    return 0;

}


Output:

Enter the radius value of the circle: 5

The area of the circle is the: 78.539818

Explanation about the above code clearly explained below:

  • #include <stdio.h>: This line includes the standard input/output library for C programming.
  • #include <math.h>: This line includes the math library for mathematical calculations.
  • int main() {: This line is the starting point of the C program. It declares the main function.
  • float radius, area;: This declares two float variables, radius and area, to store the user input and calculated area respectively.
  • printf("Enter the radius of the circle: ");: This line prints a message asking the user to enter the radius of the circle.
  • scanf("%f", &radius);: This line reads the user input for the radius and stores it in the radius variable.
  • area = M_PI * pow(radius, 2);: This line calculates the area of the circle using the M_PI constant from the math library and the pow function to calculate the square of the radius.
  • printf("The area of the circle is: %f\n", area);: This line prints the calculated area of the circle.
  • return 0;: This line indicates the end of the main function and returns 0, indicating successful execution of the program.

for any question or program or anything asking in the comment box to tell him



C++ code

#include <iostream>
#include <cmath>

int main() {
    float radius, area;

    std::cout << "Enter the radius of the circle: ";
    std::cin >> radius;

    area = M_PI * pow(radius, 2);

    std::cout << "The area of the circle is: " << area << std::endl;

    return 0;
}

Output:

Enter the radius of the circle: 5

The area of the circle is: 78.5398

Explanation about the above code clearly explained below:

  • #include <iostream>: This line includes the input/output stream library for C++ programming.
  • #include <cmath>: This line includes the cmath library for mathematical calculations.
  • int main() {: This line is the starting point of the C++ program. It declares the main function.
  • float radius, area;: This declares two float variables, radius and area, to store the user input and calculated area respectively.
  • std::cout << "Enter the radius of the circle: ";: This line prints a message asking the user to enter the radius of the circle.
  • std::cin >> radius;: This line reads the user input for the radius and stores it in the radius variable.
  • area = M_PI * pow(radius, 2);: This line calculates the area of the circle using the M_PI constant from the cmath library and the pow function to calculate the square of the radius.
  • std::cout << "The area of the circle is: " << area << std::endl;: This line prints the calculated area of the circle.
  • return 0;: This line indicates the end of the main function and returns 0, indicating successful execution of the program.

for any question or program or anything asking in the comment box to tell him

Post a Comment

0 Comments

Close Menu