Advertisement
brainuser5705

printing out primes

Apr 24th, 2021
62
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Program to print prime numbers
  2. #include <stdio.h>
  3. #include <stdbool.h>
  4.  
  5. int main ()
  6. {
  7.     int    p, d;
  8.     _Bool  isPrime;
  9.  
  10.     for ( p = 2; p <= 50; ++p ) {
  11.         isPrime = 1;
  12.  
  13.         if (p!=2 && p%2==0){
  14.             isPrime = 0;
  15.         }else{
  16.             for ( d = 3; d < p/2; d+=2 )
  17.             if ( p % d == 0 )
  18.                 isPrime = 0;
  19.         }
  20.        
  21.         if ( isPrime != 0 )
  22.             printf ("%i ", p);
  23.         }
  24.     printf ("\n");
  25.     return 0;
  26.    
  27.  
  28.     return 0;
  29. }
  30.  
Advertisement
RAW Paste Data Copied
Advertisement