C Programming

C Program – Find a number is prime or not

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 :)

Found a mistake or something out of date? Tell us →

Written by

chandrashekhar

Founder of onlinetutorialspoint.com. Enterprise architect with 15+ years in healthcare technology, designing and running systems on AWS and Azure. Writes about building real things with AI, local AI hardware and cloud certifications.

Keep reading

Ask a question or leave a comment