Print prime number – C Program

Prime number – C Program

Write a c program for print the prime number up to given number

Prime number is the number who divisible only by itself. The 2 is the minimum and first prime number.

In prime number series only 2 is even, all the rest of the prime number are odd.

The prime numbers are : 2 3 5 7 11 13 17 19………

Here is the example for print prime number up to inputted number. means we input any number and the result in display prime numbers up to that inputted number in c program.

#include<stdio.h>
#include<conio.h>
 
void main()
{
   int n, i = 3, count, a;
 
   printf("Enter the number for dispaly prime number :\n");
   scanf("%d",&n);
 
   if ( n >= 1 )
   {
      printf("The Prime numbers are :\n");
      printf("2\n");
   }
 
   for (count = 2 ; count <= n ;)
   {
      for (a = 2 ; a <= i - 1 ; a++)
      {
         if (i%a == 0 )
            break;
      }
      if (a == i)
      {
         printf("%d\n",i);
         count++;
      }
      i++;
   }
 
}

The prime number of given number c program out put is :

Enter the number for dispaly prime number :
9

The Prime numbers are :
2
3
5
7
11
13
17
19
23

 

Author: Meera Academy

Leave a Reply

Your email address will not be published. Required fields are marked *