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
In 1981, Ian Murphy broke into the AT&amp;T online computer system and changed their clocks, allowing people to make calls durin
poizon [28]
A. intentionally or recklessly disrupt, degrade, or destroy information or services on the computer
5 0
2 years ago
Which font attribute would be most appropriate to make a papers heading stand out?
eimsori [14]

If you want your heading to pop out I would go for bold Becuase it shows the letters darker and bigger which would make the heading the center of attention.

7 0
3 years ago
Read 2 more answers
Lactic acid (ch3ch(oh)cooh) has one acidic hydrogen. a 0.10 m solution of lactic acid has a ph of 2.44. calculate ka.
sammy [17]

The answer is : Ka=0.000137

HA -> H+ + A-

0.10 x x

0.10-x +x +x

[H+]= 10^-2.44 = 0.00363

x= 0.00363

(0.00363)(0.00363)/(0.10-0.00363) = 0.000137

Ka=0.000137

5 0
3 years ago
By the mid-1990s, how did revenue generated from video games compare to revenue generated from movies?
Vlad [161]

By the mid-1990s, the revenue generated from video games was two and a half times the revenue generated from movies.

Research shows that in 1994, the revenue generated from arcades in the United States was about $7 billion quarterly while the revenue generated from home console sales was about $6 billion dollars.

When combined, this revenue from games was two and a half times the amount generated from movies.

Learn more about video games here:

brainly.com/question/8870121

4 0
2 years ago
A potential customer wants to find out how blockchain can benefit their company and why they should use Accenture’s Multi-party
grandymaker [24]

Answer:

maybe blockchain can help them in term of security

6 0
3 years ago
Other questions:
  • The World Wide Web consists of interconnected computer networks throughout the world that everyone can use. True or False
    13·2 answers
  • Generally speaking, mobile sites are good for acquiring new customers and inspiring new relationships while mobile apps are good
    6·1 answer
  • _ effects determine how slide elements disappear
    11·1 answer
  • Describe the Software Development Life Cycle. Describe for each phase of the SDLC how it can be used to create software for an E
    14·1 answer
  • Why are high-quality transformers wound with large diameter wire?
    8·1 answer
  • What aspect of web design is Gloria following when she uses the same color scheme throughout a web page?
    12·1 answer
  • Write an algorithm to determine a students final grade and indicate whether it is passing or failing .the final grade is calcula
    12·1 answer
  • Ask the user for a total food bill and then find the new total after 6% tax and a tip of the users choice (15, 18, 20%) in pytho
    8·1 answer
  • Write a program that asks the user how many numbers will be entered and then has the user enter those numbers. When this is done
    7·1 answer
  • Which statement about intellectual property is true? (CSI-7.6) Group of answer choices It is okay to use code you find on the in
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!