Computer Science, asked by ivytaylor598, 1 year ago

Write a program to generate the prime nos upto 100 except those which are greater than 40 and less than 60

Answers

Answered by manthanlal2318
0

Answer:

#include <stdio.h>

int main()

{

   int i, j, flag = 0;

   for(i=2; i<=100; i++){  //starting my loop from 2 as because the smallest prime no is 2

       if(i>40 && i<60){   //checking the condition, that if the no comes between 40 to 60 than skip that no.

           continue;

       }

       else{

           for(j=1; j<=i; j++){    // performing a loop to traverse from 1 to the selected traversing no.

               if(i%j==0)

                   flag++; //counting the no. of divisor

           }

           if(flag==2) //if the no. is prime, it will have two divisor, 1 and the no. itself

               printf("%d  ", i);

           flag = 0;   //reseting the flag value for next loop

       }

       

   }

   return 0;

}

Similar questions