Add a bit of debugging info to shed some light on things:
#include <stdio.h>
int main() {
int i, x;
scanf("%d", &x);
for (i = 2; i < x; i++)
{
printf("Checking if divisible by %d\n", i);
if (x % i == 0) {
printf("Not a Prime Number");
break;
}
else {
printf("Is a Prime Number");
break;
}
}
}
#include <stdio.h>
int main() {
int i,x,flag=0;
scanf("%d", &x);
for (i = 2; i <= x/2; i++)
{
printf("Checking if divisible by %d\n", i);
if (x % i == 0) {
printf("Not a Prime Number");
flag=1;
break;
}
}
if(flag==0) {
printf("Is a Prime Number");
}
return 0;
}
Yes just comment the statement which is printing Checking if divisible by
#include <stdio.h>
int main() {
int i, x,flag=0;
scanf("%d", &x);
for (i = 2; i <= x/2; i++)
{
//printf("Checking if divisible by %d\n", i);
if (x % i == 0) {
printf("Not a Prime Number");
flag=1;
break;
}
}
if(flag==0) {
printf("Is a Prime Number");
}
return 0;
}