jweinst1
12/14/2017 - 7:49 PM

using goto statement to solve factorial

using goto statement to solve factorial

#include <stdio.h>

//facilitating iteration  with goto statement.

int factorial(int i)
{
  int total = 1;
  fact_step:
     if(!i) goto end;
     else {
       total *= i--;
       goto fact_step;
     }
  end:
    return total;
}



int main(void) {
  printf("The factorial of 3 is %d\n", factorial(3));
  return 0;
}