Check Number is Prime or not using C Programming Language

 #include   <stdio.h>

#include   <stdbool.h>

#include   <math.h>


int  main() {

int  number;

printf( "isPrime? \n" );

printf( "\n" );

printf( "Enter the number to be checked \n" );

scanf( "%d" , &number);

printf( "\n" );

bool  isPrime =  true ;

int  i;


//Prime number checker

if  (number > 1) {

for  (i = 2; i <= sqrt(( double )number); i++) {

if  (number % i == 0) {

isPrime =  false ;

break ;

}

}

}

else  {

isPrime =  false ;

}


if  (isPrime) {

printf( "It is a Prime Number \n" );

}

else  {

printf( "Not a Prime Number \n" );

}

printf( "\n" );

return  0;

}


You may like these posts