Connecting Tech Pros Worldwide Forums | Help | Site Map

c++ program that can calculate big (8-digit) factorials

Newbie
 
Join Date: Jan 2008
Posts: 6
#1: Jan 14 '08
hi
i have to write a c++ program that can calculate big factorials using a vector sized 17(for example c)and c[i] can hold 8 digits
i need help
plz help me

epots9's Avatar
Moderator
 
Join Date: May 2007
Location: Canada
Posts: 1,313
#2: Jan 14 '08

re: c++ program that can calculate big (8-digit) factorials


Moved to the C Forums where the resident experts can better assist you.

**Moved from Programming Challenges.
sicarie's Avatar
Moderator
 
Join Date: Nov 2006
Location: USA
Posts: 3,929
#3: Jan 14 '08

re: c++ program that can calculate big (8-digit) factorials


Quote:

Originally Posted by ladan

hi
i have to write a c++ program that can calculate big factorials using a vector sized 17(for example c)and c[i] can hold 8 digits
i need help
plz help me

Sure, what do you have so far?
Newbie
 
Join Date: Jan 2008
Posts: 6
#4: Jan 15 '08

re: c++ program that can calculate big (8-digit) factorials


Quote:

Originally Posted by sicarie

Sure, what do you have so far?

i have done sth abt it but my code is incorrect
i do not know how to gather all the informations that i have.i wrote sthe like this:
int a ; //the number which we want to calculate its factorial
int n=a;int b=a;
for(int i=16;i>=0;i=i+1)
{ c[i]=n;
while(c[i]<p) //p is e+9
{ b=b-1;
c[i]=(c[i]*(b%10))+(c[i]*(b/10)*10);
}
}
but i know its wrong
could you plz help me starting a new code?
Expert
 
Join Date: Aug 2007
Posts: 674
#5: Jan 15 '08

re: c++ program that can calculate big (8-digit) factorials


What’s wrong is your absolute lack of interest in writing readable English. And you can’t use code tags. Not that they are necessary because the code you posted is nonsense. Obviously it’s wrong. But then you just request new code?

It’s obvious you have no clue what you’re doing. The only way we can help you is by outright doing part or all of the work for you. That doesn’t fly here. You’re not struggling because you hit a wall in your efforts. You’re struggling because you have no idea how to write C++ code and can’t do a thing.

Perhaps you should start going over C++ books quickly. Then work with your professor, teacher, or the like to slowly build up a program. We don’t do other people’s work. We only assist, and we can’t assist you if you don’t even know how to start writing code.
Newbie
 
Join Date: Jan 2008
Posts: 6
#6: Jan 15 '08

re: c++ program that can calculate big (8-digit) factorials


if you read my reply completely i wrote:can you HELP me start a new code i didnt wrote:WRITE a new code for me.
i have written many codes in c++ but this one is realy confusing me.i have the idea of how to do it but i dont know how to assemble things that i know
what i wrote was not the whole code and i didnt want anyone to do my work
i just needed someone to direct me how to start
i just want someone to guide me and tell me how to start !!!!
anyway thanks for your reply
Expert
 
Join Date: Aug 2007
Posts: 674
#7: Jan 15 '08

re: c++ program that can calculate big (8-digit) factorials


Let’s start by figuring out what the constraints of your program are. Can you use third party libraries like Blitz or GMP or the like? What exactly do you mean by 8 digit factorials? Do you have to use vectors?

Quote:
i just needed someone to direct me how to start
i just want someone to guide me and tell me how to start !!!!
Details details. Screaming “help, help” in poor grammatical English doesn’t help. We’ll try a bit, but if you keep making it harder for us to help you, you only have yourself to blame. Try and write proper grammatical sentences. Capitalize and the like. It makes your post readable and helps us understand you better. Use code tags when posting code, so we can read code properly. Describe your problem properly.

Raymond’s article makes for excellent reading because it shows you how to get the most amount of help from people. That is what you want in the end, right? You want people helping you.
Newbie
 
Join Date: Jan 2008
Posts: 6
#8: Jan 16 '08

re: c++ program that can calculate big (8-digit) factorials


Iknow my english is not good,but thats all i can do.
I must use vectors:
const int size=17;
vector<int> c(size);
for example when we want to calculate 14!,we do sth like this:
sum=14*(13%10)+14*(13/10) and we keep doing thist till the sum reaches the point that it has 8 digits,this sum will be c[16] and we keep doing this until we reach 14!.then:
c[16]=c[16]+c[15];but c[i] can only hold 8 digits and if this sum has more than 8 digits the remains will go to c[15]
but i dont know how to assemble all these together
RedSon's Avatar
Site Moderator
 
Join Date: Jan 2007
Location: America
Posts: 3,392
#9: Jan 16 '08

re: c++ program that can calculate big (8-digit) factorials


Quote:

Originally Posted by ladan

Iknow my english is not good,but thats all i can do.
I must use vectors:
const int size=17;
vector<int> c(size);
for example when we want to calculate 14!,we do sth like this:
sum=14*(13%10)+14*(13/10) and we keep doing thist till the sum reaches the point that it has 8 digits,this sum will be c[16] and we keep doing this until we reach 14!.then:
c[16]=c[16]+c[15];but c[i] can only hold 8 digits and if this sum has more than 8 digits the remains will go to c[15]
but i dont know how to assemble all these together

Lets all try to stay calm...

ladan, instead of trying to write to code out, why don't you concentrate on the design of your algorithm. First clearly state the problem you are trying to solve. Then list a few steps that you need to do to accomplish solving the problem. Then look at each step and see if you can break it down into smaller steps. Then look at those smaller steps and do the same thing. If you get stuck on a step then post what you have and clearly state what part you are stuck on. After you have your steps written out then you can start creating pseudo-code for those steps. Then you can post your pseudo-code and ask the experts to look at it and give their opinion of it.

After all that you should be able to write the code fairly easily and if you get stuck on syntax or what datatype to use or how to do fancy things with vectors that is where we can help.
RedSon's Avatar
Site Moderator
 
Join Date: Jan 2007
Location: America
Posts: 3,392
#10: Jan 16 '08

re: c++ program that can calculate big (8-digit) factorials


Quote:

Originally Posted by ladan

hi
i have to write a c++ program that can calculate big factorials using a vector sized 17(for example c)and c[i] can hold 8 digits
i need help
plz help me

Here is an example, I'll do this for you once because I'm feeling nice, this is more then I have done for practically anyone ever (sicarie can attest to that):

Problem: Write a program that can calculate big factorials. It must be in c++ and must use Vectors.

1. Get input from the user.
2. Take that number "n" and multiply it by "n -1"
3. Take that product and multiply it by "n-1-1..." and so on until n is 1.
4. Return the product.

Now how can steps 2 and 3 be further broken down? How can a Vector be used to help you solve this problem?
Newbie
 
Join Date: Jan 2008
Posts: 6
#11: Jan 17 '08

re: c++ program that can calculate big (8-digit) factorials


thanks for ur help.I found the solution
anyways thanks for guiding me
Newbie
 
Join Date: Jan 2008
Posts: 6
#12: Jan 17 '08

re: c++ program that can calculate big (8-digit) factorials


I will do what u say,and I will try to stay calm next time
this problem was realy confusing me but I found the solution
Reply