Just wondering if someone can tell me why there is no output for this program.
I've attempted to debug it but a fresh view would be appreaciated.
Code:
/* divisors.c -- nested ifs display divisors of a number */
#include <stdio.h>
#include <stdlib.h>
#define NO 0
#define YES 1
int main(void)
{
long num, div;
int prime; /*potential divisors */
printf("Please enter an integer for analysis; ");
printf("Enter q to quit.\n");
while (scanf("ld", &num) == 1)
{
for (div = 2, prime = YES; (div * div) <= num; div++)
{
if (num % div == 0)
{
if ( (div * div) != num)
printf("%ld is divisible by %ld and %ld.\n", num, div, num / div);
else
printf("%ld is divisible by %ld.\n", num, div);
prime = NO; /* Number is not prime */
}
}
if (prime == YES)
printf("%ld is prime.\n", num);
printf("Please enter another integer for analysis; ");
printf("Enter q to quit.\n");
}
system("pause");
return (0);
}