Hello, I'm quite new to the C language and I wanted to try and make a program that'll input a number from the user and tell him whether it is prime or not.
This is the program I tried to build:
Quote:
#include <stdio.h>
#include <conio.h>
#include <math.h>
int main()
{
int i, number, square;
printf("Enter a potential prime:\n");
scanf("%d", &number);
square = sqrt(number);
for (i=2; i < square; i++)
{
if(number%i==0)
printf("Number is prime.\n");
else
printf("Number is not prime because it is divisible by %d", i);
}
getch();
return 0;
}*
|
No matter what number I input it tells me it is divisible by 2. Please help me if you know how to fix it...
Thanks ahead.
Cloudbreak.