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;

}

Comments

Popular posts from this blog

Umbrella activities in Software Engineering

Operating System | Best Definition of Opetating System