Thursday, 9 November 2017

11-D prog-11 Write a algorithim and program to check the given number is prime or not


Algorithm:
Input
1) x
output
1) The given no is prime/ not prime.

Method:
1) Start
2) Read x
3) Write x
4) //logic
 for(y=2; y<x; y++)
   begin
           r= x%y;
           if (r==0)
           begin
                  L=1;
                  break;
            end
     end
5. if(L==1)
    write  "The given number is not a prime";
    else
    write "The given number is prime";
6. stop

Example:
1. x= 4    the given number is not prime
2. x= 9  the given number is not prime
3. x=17 the given number is pirme
     

No comments:

Post a Comment