C program to print prime numbers between 1 to n.

In this post we are going to write a simple C program which prints prime numbers from 1 to n. Prime numbers are those numbers whose only two whole-number factors are 1 and itself. 
-1 is not a prime number


#include<stdio.h>
#include<conio.h>
int main()
{
 int nr,n,div,p;
 printf("Enter any number: ");
 scanf("%d", &nr);
 for(n=2; n<=nr; n++)
 {
  for(div=2; div<n; div++)
  {
   if(n%div==0)
   {
     p=0;
     break;
   }
   p=1;
  }
  if(p)
    printf("\t%d",n);
 }
 return 0;
}

Comments

Popular posts from this blog

Configure IP address on Oracle Linux

Oracle Directory Object

TIME INTERVAL in Oracle