Hi, I just started very basic Arduino programming this last week in class, and I’m having trouble with a project. We’re supposed to program Arduino to compute factorials from 0 to 10 and spit out the info like this:

"

The factorial of 0 is 1

The factorial of 1 is 1

The factorial of 2 is 2

The factorial of 3 is 6

"

This is the code I’ve put in:

"int n, m;

void setup() {

// put your setup code here, to run once:

Serial.begin(9600);

}

void loop() {

// put your main code here, to run repeatedly:

n = 1;

m = 10;

int fact = 1;

for(int x = n; x <= m; x++)

{

fact = fact * x;

Serial.print("The Factorial of “);

Serial.print(x);

Serial.print(” is ");

Serial.println(fact);

delay(1000);

}

}

"

I’ve made progress to be able to compute factorials up to 7!, but once I hit 8 it gets weird. This is what I’m getting from the Serial Monitor:

"

The Factorial of 1 is 1

The Factorial of 2 is 2

The Factorial of 3 is 6

The Factorial of 4 is 24

The Factorial of 5 is 120

The Factorial of 6 is 720

The Factorial of 7 is 5040

The Factorial of 8 is -25216

The Factorial of 9 is -30336

The Factorial of 10 is 24320

The Factorial of 1 is 1

The Factorial of 2 is 2

The Factorial of 3 is 6

The Factorial of 4 is 24

[etc.]

"

Can someone help me understand why this is? Thanks for all suggestions and advice!

BTW, I’m pretty sure I know how to include 0!, I’ll do that at the end.