Wednesday 28 September 2011


CHECK  POSITIVE OR NEGATIVE NUMBER

Aim:
To write a shell program to check the given number is positive or negative.

Algorithm:

1. Start the program.
        2. Get the number n from the user.
        3. C  heck if n <0 then print negative number.
            If n > 0 then print positive number otherwise print zero.
       4. Stop the program.
Program:

echo ‘Enter a number”
         read n
         if test $n-gt0
         then
         echo “Positive number”
         elif test $n -it 0
         then
         echo “Negative number”
         else
echo “zero”

Output :
 enter the number:72 (positive number)
enter a number : -3 (negative)

Result:
 Thus the program is written and executed for checking the given number positive or
Negative.

0 comments:

Post a Comment