Print square of any number by function (input in the user define function)
# include <iostream>
using namespace std;
int sq() // name of function
{
int number;
cout<<"Please enter the number: "; // message for user
cin>>number;
int sq; // variable
sq=number*number; // formula for square
return sq; // the value return from a variable sq
}
void main ()
{
int ans=sq(); // here the function call
cout<<"The square is: "ans<<endl<<endl;
}
using namespace std;
int sq() // name of function
{
int number;
cout<<"Please enter the number: "; // message for user
cin>>number;
int sq; // variable
sq=number*number; // formula for square
return sq; // the value return from a variable sq
}
void main ()
{
int ans=sq(); // here the function call
cout<<"The square is: "ans<<endl<<endl;
}
Comments
Post a Comment