C++ Function which prints square of given number.

//C++ Function which prints square of given number.

#include <iostream>
using namespace std;
int sqr(int a);
int main() 
{
	int a, ans;
	cout << "Enter a digit to find square : ";
	cin >> a;
	ans=sqr(a);
	cout << "\n\nSquare of "<< a <<" : "<<ans;
               return 0;
}
int sqr(int a)
{
	int ans;
	ans=a*a;
	return ans;
}

Output :
Enter a digit to find square : 5

Square of 5 : 25



Leave a comment