Thursday 16 August 2012

Loop control structure027


Input a number and store all the prime number between that number.

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

void main ( )
{
         int          n, md, no, co, fl, c = 1;
         clrscr ( );
                
         printf ("\n\t Enter a number........:"); scanf ("%d",& no);
         printf ("\n\n\t\t\t All Prime numbers from 1 to %d\n\n", no);
                       
         for ( n = 1; n <= no; n++ )
         {                                  
                      fl = 0;
                      for ( co = 2; co < n; co++ )
                      {                    
                                     md = n % co;
                                     if ( md == 0 )
                                     {                 
                                                  fl = 1;
                                                  break;
                                     }
                      }
                      if ( fl == 0 )
                                printf (" %5d \t ", n);
                                              
                      if ( c % 2500 == 0 )
                      {                                
                                     printf ("\n\t Press any key to continue");
                                     getch ( );
                                     clrscr ( );
                                     printf ("\n\n\t\t\t All Prime numbers from 1 to %d\n\n", no);
                      }                     
                      c ++;
         }
         getch ( );
}







No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...