Friday, May 3, 2019

Write a C program to check whether a given number is prime number or not.

program:


#include<stdio.h> 
main()
{
    int n,i,count=0; 
    printf("enter a number:"); 
    scanf("%d",&n); 
    for(i=2;i<n;i++)
    {
        if(n%i==0)
        {
            count++;
        }
    }
    if(count==0)
    {
        printf("the given number is a prime\n"); 
    }
    else
    {
        printf("the given number is not a prime\n");
    }
}

 output:



No comments:

Post a Comment