Wednesday 15 August 2012

Loop control structure025


Write a program to print whther a number is prime or not.

#include <stdio.h>
#include <conio.h>

void main ( )
{
        int         md, no, co, fl = 0;
        clrscr ( );
                    
        printf ("\n\t Enter a number...........:"); scanf ("%d", &no);
                 
        for ( co = 2; co < no; co++ )
        {                                    
                       md = no % co;
                       if ( md == 0 )
                       {                         
                                  fl = 1;
                                  break;
                       }                      
        }
        if ( fl == 0 )
                  printf ("\n\t It is a Prime number");
        else              
                  printf ("\n\t It is not a Prime number");
        getch ( );
}

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...