Algorithm to find a number is odd or even.

Q3. Write an algorithm to find whether a given number is odd or even.

Ans.

Integer number, quotient, remainde;

print ‘Enter number’ ;

read number ;

quotient<-number/2;

/* Since quotient is an integer, it will discard the fractional part, if any */

remainder<-number-(quotient X 2);

If remainder = 0

print ‘Number is even’;

else

print ‘Number is odd’;

Leave a Reply

Your email address will not be published. Required fields are marked *

70 Views
%d bloggers like this: