Generate Prime no in Turbo C


  • #include<stdio.h>
     
    int main()
    {
       int n, i = 3, count, c;
     
       printf("Enter the number of prime numbers required\n");
       scanf("%d",&n);
     
       if ( n >= 1 )
       {
          printf("First %d prime numbers are :\n",n);
          printf("2\n");
       }
     
       for ( count = 2 ; count <= n ;  )
       {
          for ( c = 2 ; c <= i - 1 ; c++ )
          {
             if ( i%c == 0 )
                break;
          }
          if ( c == i )
          {
             printf("%d\n",i);
             count++;
          }
          i++;
       }
     
       return 0;
    }

Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Popular Posts of the Week

    Optimum Creative