top of page

A C program that will check if a number is a prime number or not

  • Writer: Nelson John
    Nelson John
  • Nov 27, 2017
  • 1 min read

#include<stdio.h>

int main() {

int num, i, count = 0;

printf("Enter a number: ");

scanf("%d", &num);

for (i = 2; i <= num / 2; i++) {

if (num % i == 0) {

count++;

break;

}

}

if (count == 0)

printf("%d is a prime number", num);

else

printf("%d is not a prime number", num);

return 0;

}

Facebook: ayamnelrodinho1@gmail.com

Yahoo: talk2nelsonjohn2dat@yahoo.com

Whatsapp: +2349034595610

PLEASE KINDLY SHARE WITH FELLOW PROGRAMMERS AND ALSO SUBSCRIBE TO MY BLOGs PAGE FOR MORE FEEDS.


 
 
 

Comentarios


bottom of page