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