> Write a C program that calls your factorial function from within a loop in the main () function?

Write a C program that calls your factorial function from within a loop in the main () function?

Posted at: 2014-12-18 
include

/* Your factorial function goes here. Sounds like you wrote it for

* a previous homework assignment. */

static int fact(int n) { ... }

/* Your assignment is badly worded, but it sounds like the program

* has a single input which is the integer where it starts printing

* the table. */

int main (int argc, char *argv[]) {

int n;

int f, prev;

/* You should validate the input, but I'll assume it's there &

* can be parsed to a non-negative integer. */

n = atoi (argv[1]);

prev = -1;

f = fact (n);

/* Also, your assignment mentions the

* maximum vaue for which you can calculate a factorial.

* I don't know if your class hard-coded that or has some

* other way, so I'll assume that, as long as a larger N

* leads to a larger factorial, we're good. */

while (prev < f) {

printf ("\n%9d %9d", n, f);

prev = f; f = fact (n); ++n;

}

return 0;

}

I would assume that your teacher expects that you have the resources (textbook, handouts, class lectures) to be able to do this on your own. You should try to do the assignment and if you have trouble then post your code and explain where you are having the problem.

People are willing to help when you show some effort.

Call your factorial function from within a loop in the main () function.

The loop should increment the input from 0 until the maximum integer for which

we can compute/store its factorial. Print the numbers and their factorials, i.e., your

columns will be n and n!.