Computer Science, asked by padhytanmayee, 2 months ago

write a program to compute the circumference of a circle​

Answers

Answered by ajayyd463
1

Answer:

int main() { int rad;

float PI = 3.14, area, ci; printf("\nEnter radius of circle: ");

scanf("%d", &rad); area = PI * rad * rad;

printf("\nArea of circle : %f ", area); ci = 2 * PI * rad;

printf("\nCircumference : %f ", ci); return (0);

Explanation:

Answered by purveshKolhe
2

\bf{\underline{Answer::}}

import java.util.Scanner;

public class Main {

   public static void main(String[] args) {

       Scanner sc = new Scanner(System.in);

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

       double radius = sc.nextDouble();

       double circum = 2 * Math.PI * radius;

       circum = Math.round(circum * 100.0) / 100.0;

       System.out.println("The circumference of the circle is " + circum);

   }

}

\bf{\underline{Logic::}}

  • We first prompt the user to enter the radius of the circle.
  • Then, we calculate the circumference of the circle using the formula 2 * pi * radius. We store the value of the circumference in the circum variable.
  • To round the value to two decimal places, we multiply the value by 100.0, round it to the nearest integer using Math.round(), and then divide the result by 100.0 to get the value rounded to two decimal places.
  • Finally, we print the value of the circumference using System.out.println().
Similar questions