Check out example codes for "calculate factorial". It will help you in understanding the concepts better.

Code Example 1

int factorial(int n) {
	int res = 1, i; 
    for (i = 2; i <= n; i++) 
        res *= i; 
    return res; 
}

Learn ReactJs, React Native from akashmittal.com