Google Search

Wednesday, October 27, 2010

SIMPLE SHELL PROGRAMS EX No 4 CHECKING OF EVEN OR ODD NUMBER

Algorithm:
1. Start the program.
2. Enter the number to check even or odd,
3. Get the remainder by dividing the number by 2 (use % operator).
4. Check if remainder is zero then given number is even otherwise given number . 5. Stop the program

Program:

#ODD-EVEN checking program
echo “Enter a number”
read a
z=’expr$a%2’
if test $z —eq 0
then
echo “Even number”
else
echo “Odd number”
fi

Output:
Enter the number
22
Even Number.

0 comments:

Post a Comment