31-Write a C program to display whether number is prime or not.

Program: 31

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

#include
#include
void main()
{
    int num, i=2;
    printf("Enter a number: ");
    scanf("%d", &num);
    while(i<=num-1)
    {
        if(num%i==0)
        {
            printf("%d is not a prime number.", num);
            break;
        }
        i++;
    }
    if(i==num)
       printf("%d is a prime number.", num);
    getch();
}
Output
Enter a number: 435

435 is not a prime number.

Lokesh Kumar: Being EASTER SCIENCE's founder, Lokesh Kumar wants to share his knowledge and ideas. His motive is "We assist you to choose the best", He believes in different thinking.
Related Post
Leave a Comment

This website uses cookies.