Checking if an integer is a Prime number program too many prints
Code:
#include <math.h>
int main(void)
{
int n;
int x;
printf("enter a number to check if it is prime\n");
scanf("%d",&x);
for (n=2;n<=sqrt(x);n++) {
if((x%n)==0)
{
printf("%d not a prime number\n",x);
}
else
{
printf("%d prime number\n",x);
}
}
}
this program supposed to check if a given number prime or not,
when I enter a value bigger than 9 it gives multiple prints, moreover if all those prints say "prime number" yes it is a prime number in real, but if at least one of says "not a prime number" it is not a prime number in real
I tried many things it didn't work. I tried to find a similar code but I couldn't