Skip to main content

2. Prime Number


/* Prime Number : Prime number is a number that is a number greater than 1 and divided by 1 or itself only. */


#include <stdio.h>
int main()
{
    int n, i, j = 0;
    printf("Enter a number you want to check prime or not: ");
    scanf("%d", &n);
    for(i = 2; i < n; i++){
        if(n%i == 0)
        j++;
        break;
    }
    if(j == 0)
    printf("%d is a prime number.", n);
    else
    printf("%d is a not prime number.", n);
    return 0;
}

Comments