Monday, August 5, 2013

Program to print all prime numbers from 1 to nth number :: logic building 6




typedef enum{false,true} bool;

void main()
{

      int inputNum;
      int count;
      int number;
      int i=0;
      bool flage = true;
     
      printf("Enter the number to print all prime numbers from 1 to :: ");
      scanf("%d",&inputNum);

      for(count = 2; count <=inputNum;count++)
      {
            i = 2;
            for(i = 2 ; i < count;i++)
            {
                  if(count%i == 0)
                  {
                        flage = false;
                       
                        break;
                  }
                 
            }
            if(flage == true)
            {
                  printf("\n%d",i);
                       
            }
            flage = true;
           
      }

      getch();