home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / c / 18630 < prev    next >
Encoding:
Text File  |  1992-12-21  |  1.6 KB  |  45 lines

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