Thursday, August 18, 2011

Positive or Negative

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


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

Source Code:
#include<iostream>
#include<conio.h>
using namespace::std;
int main(void)
{
int num;
cout<<"Enter the number: ";
cin>>num;
//Deciding whether number is positive, negative or zero
if(num<0)
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;
getch();
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...