Print square of any number by function (input in the main function)
# include <iostream>
using namespace std;
int sq(int number) // argument for function
{
int sq; // variable
sq=number*number; // formula
return sq; // the value is return from sq variable
}
void main ()
{ //
int n;
cout<<"Please enter the number for square: "; // input is given in the main function
cin>>n;
int result; // variable is declare for function
result=sq(n); // the 'result' is the variable in which the return value of function is store and 'n' is the argument of function
cout<<"The square is :"<<result<<endl<<endl;
}
using namespace std;
int sq(int number) // argument for function
{
int sq; // variable
sq=number*number; // formula
return sq; // the value is return from sq variable
}
void main ()
{ //
int n;
cout<<"Please enter the number for square: "; // input is given in the main function
cin>>n;
int result; // variable is declare for function
result=sq(n); // the 'result' is the variable in which the return value of function is store and 'n' is the argument of function
cout<<"The square is :"<<result<<endl<<endl;
}
Comments
Post a Comment