Friday, June 26, 2020

C Program to Check Whether a Number is Prime or Not

C Program to Check Whether a Number is Prime or Not

Problem Statement :

 A prime number is a positive integer that is divisible only by  1 and itself. For example: 2, 3, 5, 7, 11, 13, 17

PROGRAM:

#include<stdio.h>
int main() 
{
    int i,n,count=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        if(n%i==0)
        {
            count++;        
        }
    }
    if(count==2)
        printf("It is a prime number");
    else
        printf("Not a prime number");
       
    return 0;
}
OUTPUT:
7                                                                                                                     
It is a prime number 

No comments:

Post a Comment