Algorithm for prime number or not.
Q4. Write an algorithm to find whether a given number is prime or not.
Ans.
Integer number, quotient, remainder, mid, counter;
print ‘Enter number’;
read number;
mid<-number/2;
counter<-2;
while counter<=mid
{
quotient<-number/counter;
remainder<-number – (quotient X counter);
if remainder=0
{
break;
/* This statement will terminate the loop unconditionally */
}
counter<-counter+1;
}
/* end of while loop */
If(counter-1) = mid
print ‘The number is prime’;
else
print ‘The number is not prime’;