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
Triss [41]
3 years ago
12

Write a function to add two large integers of any length, say up to 200 digits. A suggested approach is as follows: treat each n

umber as a list(array), each of whose elements is a block of digits of that number (say block of 1 to 4 digits, your choice). For example the integer 123456789101112 might be stored with N(1)
Computers and Technology
1 answer:
Gekata [30.6K]3 years ago
5 0

Answer:

see explaination

Explanation:

/ C++ program to find sum and product of two large numbers.

#include<bits/stdc++.h>

#include<cstring>

using namespace std;

// Multiplies str1 and str2

string big_multiply(string num1, string num2)

{

int n1 = num1.size();

int n2 = num2.size();

if (n1 == 0 || n2 == 0)

return "0";

// will keep the result number in vector

// in reverse order

vector<int> result(n1 + n2, 0);

int i_n1 = 0;

int i_n2 = 0;

// Go from right to left in num1

for (int i=n1-1; i>=0; i--)

{

int carry = 0;

int n1 = num1[i] - '0';

// To shift position to left after every

// multiplication of a digit in num2

i_n2 = 0;

// Go from right to left in num2

for (int j=n2-1; j>=0; j--)

{

// Take current digit of second number

int n2 = num2[j] - '0';

int sum = n1*n2 + result[i_n1 + i_n2] + carry;

carry = sum/10;

// Store result

result[i_n1 + i_n2] = sum % 10;

i_n2++;

}

// store carry in next cell

if (carry > 0)

result[i_n1 + i_n2] += carry;

i_n1++;

}

// ignore '0's from the right

int i = result.size() - 1;

while (i>=0 && result[i] == 0)

i--;

if (i == -1)

return "0";

// generate the result string

string s = "";

while (i >= 0)

s += std::to_string(result[i--]);

return s;

}

// Function for finding sum of larger numbers

string findSum(string str1, string str2)

{

if (str1.length() > str2.length())

swap(str1, str2);

// Take an empty string for storing result

string str = "";

// Calculate lenght of both string

int n1 = str1.length(), n2 = str2.length();

int diff = n2 - n1;

// Initialy take carry zero

int carry = 0;

// Traverse from end of both strings

for (int i=n1-1; i>=0; i--)

{

int sum = ((str1[i]-'0') +

(str2[i+diff]-'0') +

carry);

str.push_back(sum%10 + '0');

carry = sum/10;

}

// Add remaining digits of str2[]

for (int i=n2-n1-1; i>=0; i--)

{

int sum = ((str2[i]-'0')+carry);

str.push_back(sum%10 + '0');

carry = sum/10;

}

// Add remaining carry

if (carry)

str.push_back(carry+'0');

// reverse resultant string

reverse(str.begin(), str.end());

return str;

}

// Driver function code

int main()

{

string big_str1 = "1235421415454545454545454544";

string big_str2 = "1714546546546545454544548544544545";

cout <<"Sum of two number: "<< findSum(big_str1, big_str2)<<endl;

cout <<"Mutiplication of two number: "<< big_multiply(big_str1, big_str2);

return 0;

}

You might be interested in
A coworker is concerned about the veracity of a claim because the sender of an email denies sending it. The coworker wants a way
Aleks04 [339]

<u>Some recommend way to prove the authenticity of an email:</u>

  • The coworker as truthful to the company or organization he or she has to check where the same mail is sent long back to the same sender.
  • If search on emails sent item if he sends it will be well and good. Some time backup the mail will be help to proven authenticity of an email.
  • Sometimes once mail is downloaded into ms-outlook or lotus domino some time mail persists in the mail server.
  • He or she can coordinate with the mail server administrator to possible get a log file of sending mail and he can proceed as a record to management.
5 0
4 years ago
Question: 11
levacccp [35]

Answer:

The detail answer to this question is given in the explanation section.

The correct answer is .info

Explanation:

Let look as each statement

p.info.important

this is a specific  because it says

go to important property which is inside info property  which is inside P

.info  is less specific

because it will go to .info No function is  given whose property is this.

p.info

This is some what specific. As it says select .info property which is inside p

4 0
3 years ago
People who work the total hours for which they get paid have
Troyanec [42]
Perfect attendance and a salary
7 0
3 years ago
Read 2 more answers
How were the pages made to create the Book of Kells? a. Scribes prepared the papers using a printing press. b. 185 calves were s
NeX [460]

Answer:

The answer is "Option b".

Explanation:

This is the book of the liturgical manuscript for the catholic churches, which is the four Scriptural texts now in Cambridge, Dublin, and Ireland. It is the job, which is known for the sophistication, accuracy, and elegance of that same paintings in the Classically illustrated scripts. It was been built between 800 AD by Celtic monks to build vellum 185 calves had been killed, and the incorrect option can be defined as follows:

  • In option a, This book is not used in the printing press.
  • In option c, This book is used in the liturgical manuscript.
7 0
3 years ago
If you were the IT manager for a large manufacturing company,what issues might you have with the use of opensource software? Wha
Rzqust [24]

Answer: Having the ability to change the source code to fit your needs

Explanation:

7 0
3 years ago
Other questions:
  • What is one problem you should keep in mind when researching information on the Internet?
    6·2 answers
  • Type dig www.example A in order to get the IP address of www.example. What’s the TTL of the A record returned in the response? W
    9·1 answer
  • 4. Extrusion tools in Blender® duplicate vertices while keeping the geometry connected with the original vertices. (1 point)
    7·1 answer
  • To reduce inflation, the Federal Reserve _____ the money supply. This action also causes the economy to shrink.
    13·2 answers
  • You can toggle between different types of references by pressing the ____ key on your keyboard.
    15·1 answer
  • Raul in Colombia can enter data into a spreadsheet. Olivia in England can access the spreadsheet a few minutes later and use Rau
    7·1 answer
  • 1. What makes discrimination different from harassment? (Don't give me definitions.)
    5·1 answer
  • What does it mean to say that data in an Excel table is “dynamically linked” to a chart? What are the advantages of this feature
    5·1 answer
  • Huh? translate this please. (jk, I know what it says I just want to test everyone.)
    13·1 answer
  • What is the appropriate source to find information about an organization?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!