Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

Prime Number Check Program in C

#include <stdio.h> 

main() {
  int n, i, c = 0;
  printf("Enter any number n:");
  scanf("%d", &n);

  //logic
  for (i = 1; i <= n; i++) {
      if (n % i == 0) {
         c++;
      }
  }

  if (c == 2) {
  printf("n is a Prime number");
  }
  else {
  printf("n is not a Prime number");
  }
  return 0;    
}
Program Output:
Source by www.w3schools.in #
 
PREVIOUS NEXT
Tagged: #Prime #Number #Check #Program #C
ADD COMMENT
Topic
Name
1+8 =