Object
Write a program to read a number and find its square.
Algorithm
- Declare a function int square(int x), which accepts an integer as an argument and returns an integer value.
The Function main - Declare integer variables a and b.
- Read a.
- Call the function square(a) and store the value it returns in b. (where a is the actual argument)
- Write b.
- Exit.
Defining the Function int square(int x)
(where x is the formal argument) - Declare integer variable y.
- y = x * x.
- Return (y).
- Exit.
Flowchart

C++ Source Code
// program 77
#include<iostream>
using namespace std;
int square(int x);
int main()
{
int a, b;
cout << "Enter any number: ";
cin >> a;
b = square(a);
cout << "The square of " << a << " is = " << b;
return 0;
}
int square(int x)
{
int y;
y = x * x;
return y;
}
C Source Code
/*program 77*/
#include<stdio.h>
int square(int x);
int main()
{
int a, b;
printf("Enter any numbers: ");
scanf("%d", &a);
b = square(a);
printf("The square of %d is = %d", a, b);
return 0;
}
int square(int x)
{
int y;
y = x * x;
return(y);
}
Output
Enter any number: 6
The square of 6 is = 36
