Thursday, November 22, 2012

C PROGRAM FOR PRIME NUMBER GENERATION


/* C PROGRAM FOR  PRIME NUMBER GENERATION */



#include<stdio.h>
#include<conio.h>
void main()
{
             int a,b,c=0,r;
 clrscr();
             printf("\n\t\tPRIME NUMBER");
             printf("\n\t\t~~~~~~~~~~~~~");
             printf("\nEnter range:");
             scanf("%d",&r);
             a=1;
            while(a<=r)
             {
                   b=1;c=0;
                   while(b<=a)
                   {
                      if(a%b==0)
                       c=c+1;
                       b++;
                   }           
             if(c==2)
             printf("\n %d is a prime number",a);
             a++;
           }
          getch();
}

         
















OUTPUT:



      PRIME NUMBER
                ~~~~~~~~~~~~~
Enter range: 50

 2 is a prime number
 3 is a prime number
 5 is a prime number
 7 is a prime number
 11 is a prime number
 13 is a prime number
 17 is a prime number
 19 is a prime number
 23 is a prime number
 29 is a prime number
 31 is a prime number
 37 is a prime number
 41 is a prime number
 43 is a prime number
 47 is a prime number


0 comments:

Post a Comment