Monday, November 3, 2014

First of all we all should know what is prime number?

A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself. A natural number greater than 1 that is not a prime number is called a composite number.
Example: 2,3,5,7,11 all are prime numbers.


PROGRAM

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#include<stdio.h>
int main(){
    int i,num,temp=0;

    printf("Enter a number: ");
    scanf("%d",&num);

    for(i=2;i<=num/2;i++)
    {
        if(num%i==0)
            temp=1;
    }
    if(temp==0)
            printf("%d is a Prime number",num);
    else
            printf("%d is not a Prime number",num);
    return 0;
}

0 comments:

Post a Comment