1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
aev [14]
3 years ago
7

I have to writea piece of code to calculate the factorial of somewhat large numbers so the long long type won't suffize, so usin

g vector, I stumbled upon some issues during run time:
'#include
#include

using namespace std;

vector factorial(short n)
{
vector v, z;
do
{
short m = n%10;
v.push_back(m);
}while(n/=10);

short temp = 0;
int x;
//short m = 0;

while(n-1)
{
for(auto &w : v)
{
x = w*(n-1) + temp;
temp = x/10;
z.push_back(x%10);
}
}
return z;
}

int main()
{
short T;
cin >> T;

vector v;
short temp;
while(T--)
{
cin >> temp;
v.push_back(temp);
}

vector tmp;
for(auto &w : v)
{
tmp = factorial(w);
for(auto i=tmp.end(); i!=tmp.begin(); i--)
cout << *i;
cout << endl;
}
return 0;
}
'
Computers and Technology
1 answer:
Lerok [7]3 years ago
6 0
Your second comment is a solution that is actually almost right!!!
Here's what you should fix:

- The array v[200] should be initialized to all zeros, otherwise it may contain junk. You can simply do this by typing short v[200] = {}; right where you declare it.

- Your while loop should loop from all values of n all the way down to 1. So you need while(n>1) in stead of while(n--<=2)

- At the very end of the while loop, before its closing brace, add an n--; to decrement its value. Alternatively you could have created a do {} while construct.

That's it! After that it correctly calculates all 157 digits of 100!

100! = 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
You might be interested in
An
Lunna [17]

Answer:

The design of products, devices, services, or environments taking into ... algorithm. A list of steps to finish a task. ... The two options used in your binary code. ... Finding and fixing problems in an algorithm or program. ... When you write code for an event handler, it will be executed every time that event or action occurs.

8 0
3 years ago
Despite a wide variety of workplaces for those working in Human Services, all workplaces include
max2010maxim [7]

Answer:

employees and a computer

Explanation:

8 0
3 years ago
Harmful programs used to disrupt computer operation, gather sensitive information, or gain unauthorized access to computer syste
Galina-37 [17]

Answer:

Malware

Explanation:

malware is used to disrupt computer operation, gather personal info, and or gain access to private computer systems.

6 0
3 years ago
Which of the following is a method to create a new table in Access?
netineya [11]
Create table wizard !
6 0
3 years ago
What is the meaning of N.W.O​
Likurg_2 [28]

Answer:

The New World Order (NWO) in conspiracy theories is the hypothesis of a secretly emerging totalitarian world government.

8 0
3 years ago
Other questions:
  • To move to the most extreme right cell containing data in your worksheet, what basic key combination can you use?
    7·1 answer
  • 38. Which of the following best describes why e-mail spoofing is easily executed? a. SMTP lacks an adequate authentication mecha
    15·1 answer
  • To display rows from one table that do not have a corresponding row in the other table, you must create a(n) ___________________
    10·1 answer
  • A palindrome is a word or a phrase that is the same when read both forward and backward. Examples are: "bob," "sees," or "never
    7·1 answer
  • Which of these has the LEAST impact on causing the phenomenon known as acid raid?
    8·2 answers
  • Where are the worksheet tabs located
    7·1 answer
  • Do you see traffic flowing from the internet into your system or from your network to the internet? explain why or why not:
    6·1 answer
  • Suppose a computer has 1GB of memory. Operating System takes 256 MB of memory. Imagine each task takes up 196 MB of memory and t
    12·1 answer
  • (k + 3)by the power of 3​
    9·1 answer
  • What breakthrough in sound recording facilitated stereophonic recording? Ο Α. overdubbing O B. multitrack recording O C. digital
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!