Write a program to find the volume of the prism.
Example 1:
Input: base=4,height=6
Output: 96
Approach: Given a square base with side and the height of the prism.
Java
public class VolumeofPrism {public static void main(String[] args) {double base = 4;double height = 6;double
volume = volumePrism(base, height);System.out.println("Volume of Prism is " + volume);}private static double volumePrism(double base, double height) {// base is squaredouble baseArea = base * base;// volume baseArea*heightdouble volume = baseArea * height;return volume;}}
C++
#include <bits/stdc++.h>using namespace std;//function to find the volume//of prismdouble volumePrism(double base,double height){//base is squaredouble baseArea=base*base;//volume baseArea*heightdouble volume =baseArea*height;return volume;}int main(){double base=4;double height=6;double volume =volumePrism(base,height);cout<<"Volume of Prism is ";cout<<volume<<"\n";return 0;}
Example 1:
Input: length=4,width=5,height=6
Output: 120
Approach: Given a rectangle base and the height of the prism.
Java
public class VolumeofPrism {public static void main(String[] args) {double length = 4;double width = 5;double height = 6;double volume = volumePrism(length, width, height);System.out.println("Volume of Prism is " + volume);}private static double volumePrism(double length, double width,double height) {// base is rectangledouble baseArea = length * width;// volume baseArea*heightdouble volume = (baseArea * height);return volume;}}
C++
#include <bits/stdc++.h>using namespace std;//function to find the volume//of prismdouble volumePrism(double length,double width,double height){//base is rectangledouble baseArea=length*width;//volume baseArea*heightdouble volume =(baseArea*height);return volume;}int main(){double length=4;double width=5;double height=6;double volume =volumePrism(length,width,height);cout<<"Volume of Prism is ";cout<<volume<<"\n";return 0;}
No comments:
Post a Comment