Monday , January 22 2018
Home / c-program / C Program – Find a number is prime or not

C Program – Find a number is prime or not

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

is Prime or not ?


#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; 
}

Enter any number : 5
5 is prime number 🙂

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

Happy Learning 🙂

About chandrashekhar

Hi
Folks,
you have reach this so far, that shows you like what you are learning. Then why don’t you support us to improve for bettor tutorials by leaving your valuable comments and why not you keep in touch with us for latest updates on your favorite blog @ facebook , twitter , Or Google+ ,

Recommended

C Program – Addition of two Matrices Example

C Program to Addition of two Matrices. Addition of two Matrices : Happy Learning 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *