Check whether a number is prime in C language

www.la‮ttu‬uri.com
Check whether a number is prime in C language

A prime number is a number that can only be divided by 1 or itself.
for example: 1,3,5,11,13,17

/*
Example: check if the number is prime or not in C language
*/

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <stdbool.h>

int main(int argc, char *argv[]) {

  int i, c = 0;
  int n = 11;

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

  if (c == 2) {
    printf("%d is a Prime number",n);
  }
  else {
    printf("%d is not a Prime number",n);
  }

    return 0;
}
Created Time:2017-08-28 05:41:57  Author:lautturi