62.2k views
0 votes
I need this in c program please

Computing Factorials

Lab #2

Name your program lab2.c

Start by asking the user to enter a number

between 1 and 15

Check if the user has complied.

Keep asking the user for a number between 1

and 15 until the user complies.

Then ask if recursion is desired or not.

If recursion is not desired call a function to calculate

N! (where N is the number entered)



If recursion is required call a recursive function to

calculate N! (where N is the number entered)

1 Answer

4 votes

Answer:

C code is explained below

Step-by-step 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'

User Irfan Nasim
by
5.3k points