Write a program to find the volume of the cube.
Input: side=4
Output: 64
Approach: Given side of the cube.
Volume is side*side*side
Java
public class VolumeCube {public static void main(String[] args) {double side = 4;double volume = volumeCube(side);System.out.println("Volume of cube is " + volume);}private static double volumeCube(double side) {return side * side * side;}}
C++
#include <bits/stdc++.h>using namespace std;//function to find the volume of//cubedouble volumeCube(double side){double volume =side*side*side;return volume;}int main(){double side=4;double volume =volumeCube(side);cout<<"Volume of cube is ";cout<<volume<<"\n";return 0;}
No comments:
Post a Comment