c++ conditional return example

In this c++ condition return example we made a function the accept both positive and negative numbers and produce the output of the square rout

if the number is negative the output would the square rout of absolute value otherwise the output will the square rout

at first the the program check the number if it is positive or negative

This is simple c++ conditional return example that uses if statement to check the value of the number entered

as seen in the red code below

using namespace std ;

double sqr( double x) {

if( x<0)
return sqrt(-x) ;

return sqrt(x) ;


int main() {

cout<< "Enter the number you to get square rout positive or negative "<<>
double x , result ;
cin>> x;
result = sqr (x);
cout<<"The resuly is square rout of the number you entered " <<>

return 0 ;



leave me messege