adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Program in C to find the prime number up to given number.

Program in C to find the prime number up to given number.


#include<stdio.h>
#include<conio.h>
  void main()
   {
   int i,n,n1,p;
   printf("Enter a no.:-");
   scanf("%d",&n1);
   printf("prime no.=");
   for(n=1;n<=n1;n++)
    {
    for(p=1,i=2;i<n;i++)
     {
      if(n%i==0)
       {
         p=0;
         break;
        }
     }
    if(p==1)
     printf("%3d ",n);
   }
  getch();
 }



Output:-


  

Post a Comment

0 Comments