Write a program to find the volume of the cylinder.
Input: radius=5,height=6
Output: 471
Approach: Given the radius and height of the cylinder.
Volume is PI*radius*radius*height,where PI=3.14
Java
public class VolumeofCylinder {private static final double PI = 3.14;public static void main(String[] args) {double radius = 5;double height = 6;double volume = volumeCylinder(radius, height);System.out.println("Volume of cylinder is " + volume);}private static double volumeCylinder(double radius, double height) {return PI * radius * radius * height;}}
C++
#include <bits/stdc++.h>using namespace std;#define PI 3.14//function to find the volume//of the cylinderdouble volumeCylinder(double radius,double height){double volume =PI*radius*radius*height;return volume;}int main(){double radius=5;double height =6;double volume =volumeCylinder(radius,height);cout<<"Volume of cylinder is ";cout<<volume<<"\n";return 0;}
No comments:
Post a Comment