Write a C Program To find whether the given number is prime or not. - Pratik Ghelani

Pratik Ghelani

Breaking

Friday, February 1, 2019

Write a C Program To find whether the given number is prime or not.

Program:-

#include <stdio.h> 
void main() 

    int n, i, a = 1; 
    printf("Enter a number: \n"); 
    scanf("%d", &n); 
    for (i = 2; i <= n / 2; i++) { 
        if (n % i == 0) { 
            a = 0; 
            break; 
        } 
    } 
    if (a == 1) { 
        printf("%d is a prime number", n); 
    } 
    else { 
        printf("%d is not a prime number", n); 
    } 

}


Output:-





No comments:

Post a Comment