Thursday, August 18, 2011

Positive or Negative

Problem: Check whether the entered integer is negative, positive or zero.

1. Prompt for the number.
2. Decide whether it is zero, greater than zero or less than zero.
3. Display the result.

Source Code:
using namespace::std;
int main(void)
int num;
cout<<"Enter the number: ";
//Deciding whether number is positive, negative or zero
cout<<"Given number is negative"<<endl;
else if(num==0)
cout<<"Given number is zero"<<endl;
else if(num>0)
cout<<"Given number is positive"<<endl;
return 0;

Simple enough! There is only a decision to make in this program...

0 response(s):

Respond to this Post

Your participation is appriciated...