C Programming Tutorial

Advertisements

Write program to display the series of prime number upto n in c



       #include<stdio.h>
       #include<conio.h>
       void main()
       {
               int num,i,n,temp;
              clrscr();

               printf("\nEnter any number : ");
               scanf("%d",&num);

               for(n=1;n<=num;n++)
		{
                     temp=0;

                     for(i=2;i<=n/2;i++)
                     {
                           if(n%i == 0)
                           {
                               temp=1;
                                break;
                           }
                     }

                     if(temp==0)
                        printf("%d ",n);
               }

              getch();
       }

   Output : 

              Enter any number : 50
              1 2 3 5 7 11 13 17 19 23 29 31 41 43 47




Advertisement