I have to write a program to find out n combination r (mathematics) and i have written it but when i try to call the function it doesnt work. Any help would be greatly appreciated.

Code://Edward Grant, 02159511, Assignment 5, 159.101 #include <stdio.h> int factorial (int x); int n, r, result; int main() { n=-1; r=13; while ((n<0)||(n>12)) { printf("Please enter a value for n\n"); printf("It must be between 0 and 12\n"); scanf("%i", &n); } while ((r>n)||(r<0)) { printf("Please enter a value for r\n"); printf("It must be less than your value for n and greater than 0\n"); scanf("%i", &r); } result = factorial (n); printf("The answer for %i Combination %i is %i", n, r, result); } int factorial (int x) { int counter, temp1, temp2; counter = 0; temp1 = 1; temp2 = x - counter; while (temp2 > 0) { temp1=temp1*x; counter=counter+1; } return temp1; }