Wednesday 28 September 2011


SIMPLE SHELL PROGRAMS
CHECKING OF EVEN OR ODD NUMBER

Aim:
        
To write a shell program to find the given number is even or odd.

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.
               
Result:
         Thus the program is written and executed for checking the given number is even or
         Odd.

0 comments:

Post a Comment