Advertisement
informaticage

Prime in range LAE 23012020

Jan 23rd, 2020
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.51 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main ( void ) {
  5.     int a, b;
  6.     bool isPrime;
  7.     scanf ( "%d%d", &a, &b );
  8.     if ( a > b )
  9.         printf ( "0\n" );
  10.     else
  11.     while ( a < b ) {
  12.         isPrime = true;
  13.         /// If is prime
  14.         for ( int i = 2; i <= sqrt(a); i++ ) {
  15.             if ( a % i == 0 ) {
  16.                 isPrime = false;
  17.                 break;
  18.             }
  19.         }
  20.  
  21.         if ( isPrime )
  22.             printf ( "%d ", a );
  23.         a ++;
  24.     }
  25.  
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement