Saturday, 30 December 2017

C program to print all prime number up to given number

#include<stdio.h>
int main( )
{
   int n, i, k, j;
   
   printf("Enter the number");
   scanf("%d",&n);
  
   printf("Prime number upto %d are\n",n);

   for(j=2; j<=n; j++)

    {
        k=0;
        for(i=2; i<=j-1; i++)
          {
              if(j%i==0)
                  k++;
           }
          if(k==0)
             printf("%d\n",j);
     }
  return 0;
}



No comments:

Post a Comment

Featured Post

TCS Latest Test Patern ( For On-Campus Drives )

Tata Consultancy Services is software services consulting company whose  headquarter is situated in Mumbai, India. It is the Asia’s larges...