C Program – Find a number is prime or not

By | 2017-08-20T04:24:51+00:00 August 20th, 2017|c-program|0 Comments

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

[box type=”success” align=”alignleft” class=”” width=”100%”]

Enter any number : 5
5 is prime number 🙂

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

[/box]

Happy Learning 🙂

About the Author:

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+ ,

Leave A Comment