Prime Numbers in C

Introduction
  • In this article, I am explaining how to check and print a prime number. 
Software Requirements
  • Turbo C++ or C.
Programming 
  1. #include < stdio.h >   
  2. int main()  
  3. {  
  4.     int n, i = 3, count, c;  
  5.     printf("Enter the number of prime numbers required\n");  
  6.     scanf("%d", & n);  
  7.     if (n >= 1)  
  8.     {  
  9.         printf("First %d prime numbers are :\n", n);  
  10.         printf("2\n");  
  11.     }  
  12.     for (count = 2; count <= n;)  
  13.     {  
  14.         for (c = 2; c <= i - 1; c++)  
  15.         {  
  16.             if (i % c == 0) break;  
  17.         }  
  18.         if (c == i)  
  19.         {  
  20.             printf("%d\n", i);  
  21.             count++;  
  22.         }  
  23.         i++;  
  24.     }  
  25.     return 0;  
  26. }  
Explanation
  • In the above program, the prime number can be displayed in simple manner.

    programming

    programming
Output

Output
 
Conclusion 
  • Thus, the program can be displayed and executed successfully, in a simple manner.