I have the below program to calculate factorial. It is working good for values upto 16. But when I give a value greater than 16, like 17 the output is in negative. e.g for 17 i get -288522240. Why is this?

Code:

#include<stdlib.h>
#include<stdio.h>
int factorial(int);
int main(){
int i,j;
printf("Enter a number to calculate factorial:\n");
scanf("%d",&i);
j=factorial(i);
printf("Factorial is %d\n",j);
return(0);
}
int factorial(int x){
int i, j=1;
for ( i = x; i > 1; i--)
{
j = j*i;
}
return(j);
}