We have to write a loop statement to find the absolute value of a number and then find out if it is prime or not. I am not sure what I am doing wrong but it only prints out that everything is not a prime number. Here is part of the code that I am working on
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
printf("Enter a whole number:");
for (x = 1; x <= prime; x++)
printf("%d is not a prime number\n", prime);
else printf("%d is prime\n", prime);
Also, the loop includes prime in its bounds, so as well as checking (prime % 1 == 0), it's checking (prime % prime == 0), which are always true for primes. Your loop only needs to go halfway to prime, by the way, since the smallest factor other than 1 that a composite number could have is 2.