I am a complete beginner and was just trying to apply what I have learned.
So I tried to make a C program that computes if a number passes the prime test in Fermat's little theorem.
Here is the code:
#include <stdio.h>
#include <math.h>
int main() {
double p, a, t;
printf("Enter the number tested to be prime: ");
scanf("%lf", &p);
a = 1;
t = 0;
while (a <= p && t == 0) {
t = pow(a, p) - a;
t = (int)t % (int)p;
a++;
}
if (t == 0) {
printf("prime test passed");
} else {
printf("prime test failed");
}
return 0;
}
So the problem is it works great until 10, but after that when I try it for 11 it just fails the test. Why is this happening?