Answer:
C code is explained below
Explanation:
#include <stdio.h>
// recursive function to calculate factorial
long recurivefact(int n) {
if (n>=1)
return n*recurivefact(n-1);
else
return 1;
}
// iterative function to calculate to factorial
long fact(int n){
int fact=1,i;
for (i = 1; i <= n; i++) {
fact =fact*i;
}
return fact;
}
int main()
{
int n;
char ch,choice='N';
// if choice is 'N' or 'n' keep running
while(choice=='N' || choice=='n'){\
// take user input of N
printf("Enter a number between 1 and 15:\n");
scanf("%d",&n);
// ask if user need the answer using recursive function or iterative function
printf("recursion is desired or not (Y/N):\n");
scanf(" %c", &ch);
// if ch is 'Y' or 'y' call recursive function else iterative function
if(ch=='Y' || ch=='y')
printf("%ld\n",recurivefact(n));
elsel
printf("%ld\n",fact(n));
// ask the user if he want to continue compiling(running) or not
printf("Do you wish stop compiling (Y/N):\n");
scanf(" %c",&choice);
}
return 0;
}