C Program to find a given number is prime or not.

is Prime or not ?

PrimeOtNot.c
#include<stdio.h> 
#include<math.h> 
int main(void) 
{ 
    int i,n; 
    printf("Enter any number : "); 
    scanf("%d",&n); 
 
    for(i=2; i<=sqrt(n); i++)     
        if(n%i==0) 
            break; 
 
    if(i>sqrt(n)) 
        printf("%d is prime number :)\n",n); 
    else 
        printf("%d is not a prime number :!\n",n); 
    return 0; 
}

Output:

Ternimal
Enter any number : 5
5 is prime number :)

Enter any number : 10
10 is not a prime number :!

Happy Learning 🙂

About the Author:

Founder of onlinetutorialspoint.com Love Java, Python, Shell and opensource frameworks. Follow him on twitter and facebook for latest updates.

Leave A Comment