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.
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
read n
if test $n-gt0
then
echo “Positive number”
elif test $n -it 0
then
echo “Negative number”
else
echo “zero”
Output :
enter a number : -3 (negative)
Result:
Negative.
0 comments:
Post a Comment