Write a program to find the perimeter of the square.
Example 1:
Input: side=6
Output: 24
Approach: Given side of the square.
Perimeter is 4*side.
Java
public class PerimeterofSquare {public static void main(String[] args) {double side = 6;double perimeter = perimeterSquare(side);System.out.println("Perimeter of square is " + perimeter);}private static double perimeterSquare(double side) {return 4 * side;}}
C++
#include <bits/stdc++.h>using namespace std;//function to find the perimeter//of the squaredouble perimeterSquare(double side){double perimeter=4*side;return perimeter;}int main(){double side=6;double perimeter=perimeterSquare(side);cout<<"Perimeter of square is ";cout<<perimeter<<"\n";return 0;}
No comments:
Post a Comment