There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Software Development
Tag Cloud
audio blue screen boot bsod computer cpu crash dell desktop driver drivers error excel external hard drive firefox freezes freezing hard drive hardware hijackthis internet internet explorer itunes laptop mac malware motherboard mouse network networking outlook 2007 power printer problem ram router screen slow sound trojan usb virus vista vista 32-bit windows windows vista windows xp winxp wireless wmp
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
Factorials


Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
Gor's Avatar
Gor Gor is offline
Junior Member with 4 posts.
 
Join Date: Sep 2003
15-Sep-2003, 06:31 PM #1
Question Factorials
I am beginner in C++, currently trying to figure out how to print factorials on Unix machine in C++.
Trying to print 1-50.
The Point that I got to is 20th factorial using Long Int variable.
Anyway to print factorials 1-50 in integer form, excluding any other notations (such as scientific) ?

can anyone help out or suggest any clues?

Thnx,

Gor.
Shadow2531's Avatar
Distinguished Member with 2,629 posts.
 
Join Date: Apr 2001
17-Sep-2003, 12:46 AM #2
Have you tried, converting to a string, getting rid of the decimal point and the e+xx and using a loop to print the proper amount of zeros?

You can store the length of everything after the decimal point (minus e+xx) and subtract that from the power to figure out how many zeros need to be printed after the first part.

I don't have an example in c++, but do in javascript.
__________________
10 ? "a line as the unending horizon"
20 ? "a curve as the rolling hillside"
30 ? "a point as a distant bird"
40 ? "a ray as the rising sun"
run

Last edited by Shadow2531 : 17-Sep-2003 03:44 AM.
Shadow2531's Avatar
Distinguished Member with 2,629 posts.
 
Join Date: Apr 2001
17-Sep-2003, 03:44 AM #3
Here's the
javascript example

If you input 1-21, it will just display the number because notation is not required. 22 on, notation is required and it will display the result with notation and without.

You can remove the if (i ==x) check, to display all results up to the number you input.

I only tested in opera and IE. However opera displays the incorrect answer sometimes because it rounds up the last digit before the e+.

It should give you an idea of a way you can accomplish what you want in c++.

It's far from perfect, but that should help.

Not for my sake, but someone should simplify that a whole lot and do it the proper way for javascript and c++.
__________________
10 ? "a line as the unending horizon"
20 ? "a curve as the rolling hillside"
30 ? "a point as a distant bird"
40 ? "a ray as the rising sun"
run

Last edited by Shadow2531 : 17-Sep-2003 03:54 AM.
Gor's Avatar
Gor Gor is offline
Junior Member with 4 posts.
 
Join Date: Sep 2003
17-Sep-2003, 03:52 PM #4
thnx very much for your help, I am gonna try to do the expample you suggested at first of converting to a string.
Will reply here if I succeeded.

Gor.
Shadow2531's Avatar
Distinguished Member with 2,629 posts.
 
Join Date: Apr 2001
18-Sep-2003, 03:48 AM #5
check out this page

http://www.codeproject.com/cpp/largenumber.asp

Notice the factorial example at the bottom that uses the class.
Gor's Avatar
Gor Gor is offline
Junior Member with 4 posts.
 
Join Date: Sep 2003
18-Sep-2003, 04:49 PM #6
thank you that code really helps, I can base my own implementation design on it then.

but one more thing, when I tried to test the code to see how it runs I get following error:
--------------------------------------------------------------------------
CLargeNumber::CLargeNumber[in-charge](int)
CLargeNumber:perator*=(CLargeNumber const&)
CLargeNumber:perator-=(CLargeNumber const&)
CLargeNumber::ToString() const
collect2: ld returned 1 exit status
--------------------------------------------------------------------------

perhaps my compiler can not handle it correctly,
I tried debugging, still get the same problem.

last message looks as if I have files named incorrectly, but I seem to have put the appropriate endings as in .C and .h as my compiler requires.

Gor
Shadow2531's Avatar
Distinguished Member with 2,629 posts.
 
Join Date: Apr 2001
18-Sep-2003, 10:25 PM #7
Hmm. Not sure. Maybe if I see all of the code that you have so I can test it. If it's secret, then try www.hardforum.com and goto the web development and programming forum and ask.

What compiler are you using?
Are you using an IDE also?
Gor's Avatar
Gor Gor is offline
Junior Member with 4 posts.
 
Join Date: Sep 2003
19-Sep-2003, 12:01 AM #8
http://www.codeproject.com/cpp/largenumber.asp

thats the code you refered me too, I d/led that .zip folder they had of the LargeNumbers class files.
It contained LargeNumber.C LargeNumber.h and a test.C files,
I didnt make any changed to them;
tried to run their test file to see how the class works and got those errors listed above.

Also I am using Unix based compiler, let me check name and version, yes IDE...
Compaq Tru64 UNIX V5.1B (Rev. 2650)
This machine is a Compaq Alpha ES40. It has two processors each running
at 667MHz, and 2 Gig of error correcting, primary memory (RAM).
Digital Unix

Gor
Shadow2531's Avatar
Distinguished Member with 2,629 posts.
 
Join Date: Apr 2001
19-Sep-2003, 12:14 AM #9
OK. I'll see if I can figure out what's wrong.

Edit:

I got a bunch of errors also. Not sure how to fix it. Try HardForums.

Last edited by Shadow2531 : 19-Sep-2003 04:24 AM.
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 07:37 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.