Write a program to find the area of a circle.
Formula: Area of circle = PI*radius*radius, where PI = 3.14
Approach
Java
public class AreaofCircle {public static void main(String[] args) {double radius = 10;double PI = 3.14;double area = areaCircle(radius, PI);System.out.println("Area of Circle is " + area);}private static double areaCircle(double radius, double PI) {// PI*r^2return PI * radius * radius;}}
C++
#include <bits/stdc++.h>using namespace std;#define PI 3.14//function to find the//area of circledouble areaCircle(double radius){double area=PI*radius*radius;return area;}int main(){double radius=10;double area=areaCircle(radius);cout<<"Area of circle is ";cout<<area<<"\n";return 0;}
C
#include <stdio.h>#define PI 3.14//function to find the//area of circledouble areaCircle(double radius){double area = PI * radius * radius;return area;}int main(){double radius = 10;double area = areaCircle(radius);printf("Area of circle is %lf", area);return 0;}
No comments:
Post a Comment