home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!mcsun!Germany.EU.net!math.fu-berlin.de!news.th-darmstadt.de!rbg.informatik.th-darmstadt.de!misar
- From: misar@rbg.informatik.th-darmstadt.de (walter misar)
- Subject: Re: WHAT WENT WRONG?
- Sender: news@news.th-darmstadt.de (The News System)
- Message-ID: <1992Dec18.173446@rbg.informatik.th-darmstadt.de>
- Date: Fri, 18 Dec 1992 16:34:46 GMT
- References: <10441.107.uupcb@cutting.hou.tx.us>
- Nntp-Posting-Host: rbhp63.rbg.informatik.th-darmstadt.de
- Organization: TH Darmstadt
- Lines: 32
-
- In article <10441.107.uupcb@cutting.hou.tx.us>, david.brooks@cutting.hou.tx.us (David Brooks) writes:
- > The following code is intended to compute the factorial of a given
- > number. Unfortunately it gives weird results for numbers larger than 12
- > or so... Does anyone have an idea why? I tried compiling it under Huge
- > memory model and still the same effects.
- >
- >
- > #include <stdio.h>
- >
- > main()
- > {
- > double x, y;
- >
- > printf("\nEnter number to factorialize:");
- > scanf("%d", &x);
- >
- > for(y=x-1;y>1;y--) x*=y;
- >
- > printf("\nFactorial= %d\n", x);
- > }
- >
- >
- > Undoubtedly the problem comes from playing with numbers that are too
- > big. Is there something obvious that I am overlooking here? Or is there
- > some hidden secret for dealing with big numbers that only rocket
- > scientists and C gurus are aware of? Any help is appreciated!
-
- Just use %f instead of %d (means decimal integer) in scanf and printf.
-
- --
- Walter Misar It is impossible to enjoy idling thoroughly
- misar@rbg.informatik.th-darmstadt.de unless one has plenty of work to do.
-