i have to write a program that inputs a number and determines whether the number is prime. After displaying the results, ask the user if they want to try again. At the end, print Have a nice day!
The problem I´m having is that it only tells if a number is prime the first time, when i try it more times it just says not prime for any number, i would like to see if any of you can tell me what i´m doing wrong.
[
Code:
#include <stdio.h>
#include <ctype.h>
int main()
{
int a,c=1,i,number;
char answer;
do
{
{
printf("Enter number:");
scanf("%d", &number);
getchar();
for(i=1;i<=number;i++)
{
a=number%i;
if(a==0)
{
c=c+1;
}
}
if (c==3)
printf(" PRIME NUMBER\n");
else
printf(" NOT PRIME NUMBER\n");
}
printf("Do you want to continue?(y/n)");
scanf("%c", &answer);
getchar();
} while (tolower(answer) == 'y');
{while(answer == 'n')
{
printf("Have a good day!\n"); break;
}
}
return 0;
}