Program to find the prime numbers between 2 to 50


#include<stdio.h>
main()
{
      int p, is_prime, i, primes[50], prime_index=2;
      
      primes[0]=2;
      primes[1]=3;
      
      for(p=5;p<=50;p=p+2)            //if satisfy then do below things.
      
      {
          is_prime=1;
          for(i=1; is_prime && p/primes[1]>=primes[i]; ++i)
            {
              if(p%primes[i]==0)     //if this satisfy then do below things.
                {
                is_prime=0;
                }
            }
          if(is_prime!=0)            //not be equal to 0 then do below.
            {
            primes[prime_index]=p;
            ++prime_index;
            }
      }
      
      for(i=0;i<prime_index;++i)     //if satisfy then do below things.
          {
          printf("%d",primes[i]);
          printf("\n");
          }
getch();
}

Comments

Popular posts from this blog

Customize User's Profile in ASP.NET Identity System

Lambda two tables and three tables inner join code samples