473,493 Members | 2,265 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

6 New Member
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
Jan 14 '08 #1
11 2851
epots9
1,351 Recognized Expert Top Contributor
Moved to the C Forums where the resident experts can better assist you.

**Moved from Programming Challenges.
Jan 14 '08 #2
sicarie
4,677 Recognized Expert Moderator Specialist
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?
Jan 14 '08 #3
ladan
6 New Member
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?
Jan 15 '08 #4
oler1s
671 Recognized Expert Contributor
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.
Jan 15 '08 #5
ladan
6 New Member
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
Jan 15 '08 #6
oler1s
671 Recognized Expert Contributor
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?

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.
Jan 15 '08 #7
ladan
6 New Member
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
Jan 16 '08 #8
RedSon
5,000 Recognized Expert Expert
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.
Jan 16 '08 #9
RedSon
5,000 Recognized Expert Expert
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?
Jan 16 '08 #10
ladan
6 New Member
thanks for ur help.I found the solution
anyways thanks for guiding me
Jan 17 '08 #11
ladan
6 New Member
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
Jan 17 '08 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2022
by: Joecx | last post by:
Does anyone know how to give a date (not today's date) and have the program calculate the previous monday's date from it? Any help would be appreciated. Thanks!!!! Joe
59
55663
by: Umesh | last post by:
i wrote the following program to calculate factorial: #include<stdio.h> #include<iostream.h> void main() { int i,n; long int p=1; // or long double p=1; for exponential result which I don't...
4
2216
by: damatrix1 | last post by:
28, 32,37,24,33 im not sure how to make the program calculate it
59
5761
by: Py-Fun | last post by:
I'm stuck trying to write a function that generates a factorial of a number using iteration and not recursion. Any simple ideas would be appreciated.
2
1599
by: hamady2001 | last post by:
Hello everyone this is my first post and I just started my Python class. I am stuck on an assignment...please help I have to redo the below program (from a prior assignment) to include 2 functions...
14
1463
by: Three Headed Monkey | last post by:
What does bellow C program calculate? I tried my best but couldn't figured it out. #include <stdio.h> main() { long a=1000,b=0,c=2800,d,e=0,f,g; for(;b-c;) f=a/5;...
5
2351
by: catgreg | last post by:
I am currently working on a c++ program that computes factorials and I can't get it to work for some reason, i could really use a hint, this is what I have thus far for code: #include<iostream>...
1
1598
by: ballpen1019 | last post by:
can someone help me to check any problems in this program...i cant run my program.. /* calculate depreciation using one of three different methods */ #include <stdlib.h> #include <stdio.h>...
0
7119
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6989
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7195
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6873
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7367
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5453
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1400
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.