1. ## Allowing larger numbers

If I wanted to improve this program that would allow me to enter larger integers than 10, what would I do. I think I would use long. Any help or ideas??

#include <stdio.h>

int fact(int n);

int main(void) {
int current;

printf("Enter a positive integer [to terminate enter non-positive] > ");
scanf("%d", &current);
while (current > 0) {
printf("The factorial of %d is %d\n", current, fact(current));
printf("Enter a positive integer [to terminate enter non-positive] > ");
scanf("%d", &current);
}
}

/* n is a positive integer. The function returns its factorial */
int fact(int n) {
int lcv; /* loop control variable */
int p; /* set to the product of the first lcv positive integers */

for(p=1, lcv=2; lcv <= n; p=p*lcv, lcv++);
return p;
}

2. When calculating numbers that grow so quickly you either need to set a hard limit based on the available type sizes or use a library that allows for arbitrary length numbers. The available types can only hold so much, and if you're trying to write portable code then your limits are even smaller.

3. Ok, so how do I do that. I looked at the libraries and there are over 122K search replies from "library" in our response?

4. >Ok, so how do I do that.
It depends on what you want to do. The library approach is by far the easiest, but you'll need to go to a place where you can download the library and install it. Just looking at the google search hits page won't do you much good.

If you want to write your own (never a bad idea when learning) then I suggest looking at the previous contests that we've held. The results of one of them can be adapted to suit your needs. The basic idea is to take an array of values and manually perform mathematical operations on it, thus simulating very large numbers.

5. ## ????

I don't know what you mean by contests, and if I found the right library I probably wouldn't know that. Keep in mine I have been in a C class for 3 weeks, not 3 years.

6. >I don't know what you mean by contests
While reading this post, hit the back button on your browser. Then do it again. Look for a board called Contests Board. It's under General Discussions. Look around and you'll find contest entries for arbitrary precision integers, that's what you want.

>and if I found the right library I probably wouldn't know that
Bummer.

>Keep in mine I have been in a C class for 3 weeks, not 3 years.
Then you would be better off placing a limit on N than implementing arbitrary length factorials.