C Program to Check if Given Number is Prime or Not using While loop

Write C Program to Check if Given Number is Prime or Not using While loop

//WAP to check whether the given number is prime or not

#include <stdio.h>

int main()
{
	int n;

	printf("Enter the number :--> ");
	scanf("%d", &n);

	int i = 2, count=0;

	while(i < n)
	{
		if(n % i == 0)
		{
			count++;
			break;
		}
		i++;
	}

	if(count == 1)
	{
		printf("%d is Not a Prime number", n);
	}
	else
	{
		printf("%d is a Prime number", n);
	}
	return 0;
}

Output:

Run 1:
Enter the number :--> 11
11 Prime a number

Run 2:
Enter the number :--> 65
65 is Not a Prime number

≪ Previous | Next ≫