In this example, I’ll show you how to find the perimeter of a square using pseudocode.
To calculate the area and perimeter of a square and rectangle in Pseudocode or other programming language what you any want, you have to ask to the user to side length of the square and make two variable, one for area and one for perimeter for each to perform the mathematical calculation and display the result on the output screen.
1 2 3 4 5 6 7 8 | int side,area,perimeter; read side; area=side*side; perimeter=4*side; print area; print perimeter; |
This is a simple Pseudocode that calculates the area and perimeter of a square. The program starts by declaring three integer variables: side, area, and perimeter.
The first line of executable code is the “read” statement which prompts the user to input a value for the variable “side”. The next line calculates the area of the square by multiplying the value of “side” by itself and assigns the result to the variable “area”.
The following line calculates the perimeter of the square by multiplying the value of “side” by 4 and assigns the result to the variable “perimeter”.
Then it uses the “print” statement to display the value of the variable “area” followed by the value of the variable “perimeter” on the screen.
In summary, the program prompts the user to input the length of one side of a square, calculates the area and perimeter of the square using the input value, and then displays the results on the screen.
FlowChart:
C++ Code: Write a program to calculate area and perimeter of squre in C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include <iostream> #include<stdlib.h> using namespace std; int main() { int s, area, perimeter; cout<<"Side : "; cin>>s; area = 4*s; perimeter = s*s; cout<<"Area of Square : "<<area<<endl; cout<<"Perimeter of Square : "<<perimeter; } |
This program is a C++ program that calculates the area and perimeter of a square. The program starts by including the iostream library which is used for input and output operations in C++.
It declares three integer variables: s, area, and perimeter. The first line of executable code is the “cout” statement which prompts the user to input the value of the variable “s” which represent the side of the square. The next line calculates the area of the square by multiplying 4 with the value of “s” and assigns the result to the variable “area”.
The following line calculates the perimeter of the square by multiplying the value of “s” by itself and assigns the result to the variable “perimeter”.
Then it uses the “cout” statement to display the value of the variable “area” followed by the value of the variable “perimeter” on the screen.
In summary, the program prompts the user to input the length of one side of a square, calculates the area and perimeter of the square using the input value, and then displays the results on the screen.
C# Code: Write a program to calculate area and perimeter of squre in C#
1 2 3 4 5 6 7 8 9 10 11 12 13 | static void Main(string[] args) { int s, area, perimeter; Console.Write("Side : "); s = Convert.ToInt32(Console.ReadLine()); area = 4*s; perimeter = s*s; Console.WriteLine("Area of Square : "+area); Console.WriteLine("Perimeter of Square : "+perimeter); Console.ReadKey(); } |
This is a C# program that calculates the area and perimeter of a square. The program starts by defining three variables “s”, “area”, and “perimeter” as integers.
The first line of executable code is the “Console.Write” statement which prompts the user to input the value of the variable “s” which represents the side of the square.
The next line uses the “Convert.ToInt32(Console.ReadLine())” function to read the input value of the “s” variable from the user and convert it to an integer.
Then it calculates the area of the square by multiplying 4 with the value of “s” and assigns the result to the variable “area”.
Next, it calculates the perimeter of the square by multiplying the value of “s” with itself and assigns the result to the variable “perimeter”.
The following two lines use the “Console.WriteLine” statement to display the values of the variables “area” and “perimeter” on the screen respectively.
The last line “Console.ReadKey();” is used to pause the console so that the user can read the output before the program exits.
In summary, the program prompts the user to input the length of one side of a square, calculates the area and perimeter of the square using the input value, and then displays the results on the screen.
C Code: Write a program to calculate area and perimeter of squre in C
1 2 3 4 5 6 7 8 9 10 11 12 13 | int main() { float side,perimeter; printf("enter side of square: "); scanf("%f",&side); perimeter=4*side; printf("POS: %f\n",perimeter); return 0; } |
This program is a C program that calculates the perimeter of a square. The program starts by declaring two variables: “side” and “perimeter”, which are of float data type. The first line of executable code is the “printf” statement which prompts the user to input the value of the variable “side” which represent the side of the square.
The next line uses the “scanf” function to read the input value of the “side” variable from the user.
Then it calculates the perimeter of the square by multiplying 4 with the value of “side” and assigns the result to the variable “perimeter”.
The following line uses the “printf” statement to display the value of the variable “perimeter” on the screen.
The “POS” in the printf statement is an abbreviation of perimeter of square.
In summary, the program prompts the user to input the length of one side of a square, calculates the perimeter of the square using the input value, and then displays the result on the screen.