Advertisement
informaticage

PrimeNumbers procedural

May 2nd, 2016
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.65 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <stdbool.h>
  5.  
  6. #define FINAL_NUMER 5 * pow(10, 2)
  7.  
  8. int main()
  9. {
  10.     bool isPrime;
  11.     for(int number = 3; number < FINAL_NUMER; number++)
  12.     // Runs from 0 to (5 E+50)
  13.     {
  14.         isPrime = true;
  15.         for(int i = 2; i <= sqrt(number); i++)
  16.         // Runs from 2 to the square of the parameter
  17.         {
  18.             if ((number % i) == 0) // If it finds a divisor it returns false
  19.                 isPrime = false;
  20.         }
  21.  
  22.         // If prime was not changed
  23.         if(isPrime)
  24.             printf("Prime found: %d\n", number);
  25.     }
  26.  
  27.     getchar();
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement