Area of Square in cpp



Area of Square


                    To calculate the area of the square we must know the formula area of the square is  area=side*side
                   To perform this operation in the cpp language first take the two variables as side and area to display or store the final answer. Then take the input from the user using cin, then store that values in the side as shown in the code. Pass this variable in formulae to calculate the area of the square. Then the answer is stored in area variable, display area. Refer the following code to calculate the area of the square.  

C language code to calculate the area of square:

#include<iostream.h>

#include<conio.h>

int main()
 {
   int side, area;

   clrscr();

   cout<<"\nEnter the Length of Side : ";

   cin>>side;   //to accept the side

   area=side*side;   //formula to find the area of a square

   cout<<"\nArea of Square:"<<area;   //To display the final answer

   getch();
}
-----------------------------------------------------------------------------------------
Output:
Enter the Length of Side: 5
Area of Square: 25


Area of Square in cpp Area of Square in cpp Reviewed by Amit Waghmare on October 31, 2019 Rating: 5

No comments: