Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Need help with Prime Number program

Hello,

My program has to determine if a number that I enter is a prime number - which I believe I have done. But if the number is not a prime number, it should tell me the highest divisor of this particular number. At the moment, my program gives all the divisors if the number is not a prime. And the input range must be between 1 and MAXINT. Can anyone tell me how to get MAXINT? how to declare it?

Thanks

[code]
#include
#include

void main()
{
char your_name[12];
int number;
int i;
int remainder;
int not_divisible = 1;

printf("Hello!, please enter your name: ");
scanf("%s", your_name);
printf("Enter a number: ");
scanf("%d", &number);

printf("
The number you entered is: %d", number);
printf("
");

for( i = 2; i < 10; i++ )
{
remainder = number % i;
if(remainder == 0 )
{
not_divisible = 0;
printf("This number is divisible by %d", i);
printf(" and it is not a prime number");
}
}
if(not_divisible == 1) printf("This a prime number!");
printf("
");
printf("Good-bye %s", your_name);
printf("
");
system("pause");
}
[/code]

Comments

Sign In or Register to comment.