Number is prime or not

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i=2,k=0;
clrscr();
printf("enter the number ");
scanf("%d",&n);
while(i<=n)
{
if(n%i==0)
{
k=k+1;
}
i++;
}
if(k>2)
printf("number is not prime");
else
printf("number is prime");
getch();
}

/*
output:-
-------------
enter the number 5
number is prime

*/

Comments

  1. A Prime number is a natural number greater than 1 that is only divisible by either 1 or itself. All numbers other than prime numbers are known as composite numbers.

    ReplyDelete

Post a Comment