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
What is the most accurate way to describe the excerpt?
kifflom [539]

choose the option it is a dependent clause

7 0
4 years ago
Read 2 more answers
What does a controller control?
ruslelena [56]

Answer:

b. the interface between the hard disk and the system bus

Explanation:

A controller, in the most basic computing terms, is a hardware chip or card that falls between two hardware components. Thus, a computer’s motherboard will always have a controller that interfaces with RAM, hard disk, DVD drives or other hardware components. Being an interface between two hardware devices facilitate incoming and outgoing commutations. Option B therefore, is the correct answer because it interfaces between the hard disk and sytem bus, which are both hardware components.

8 0
3 years ago
Oliver is creating anime using a less popular, traditional tool to create the style anime is known for. Which tool is Oliver usi
Makovka662 [10]
I think it might be c or b
5 0
3 years ago
Read 2 more answers
​A(n) ________ database makes it possible to store information across millions of machines in hundreds of data centers around th
Kisachek [45]

Answer:

distributed

Explanation:

According to my expertise in information technology, it seems that the type of database being described is a distributed database. Like mentioned in the question this is a database that works by saving information in data centers from various locations and information is processed through multiple database node. This allows information to be more secured, faster, and also acts as a fail-safe in case of any malfunction where data may otherwise be lost.

3 0
3 years ago
Which switch and network equipment modular connectors have replaced gigabit interface converters (gbics) as the modular connecto
Semenov [28]
The switch and network equipment modular connectors which have replaced gigabit interface converter as the modular connector of choice is small form - factor pluggable, abbreviated as SFP. It is hot swappable like GBICs but takes up very much less space and support all the networking standards that GBICs support.
5 0
4 years ago
Other questions:
  • When you want to print a page from the World Wide Web, select the print command in the _____.
    8·2 answers
  • Using the slice operator, print your first, then last name.2. Print the length of your first name.3. Assume you have two variabl
    6·1 answer
  • Gmod how to make someone admin on a lan server
    6·2 answers
  • A project manager types a document and prints it. He is using _____. hardware software hardware and software
    12·2 answers
  • For which of the following values of A and B will the expression A || B be true?
    15·1 answer
  • Anyone here codes? <br> C++, C#, Lua? Anything?
    15·2 answers
  • A regional bank implemented an automated solution to streamline their operations for receiving and processing checks/cheques. Th
    8·1 answer
  • The events that happen in a story are called the _________________.
    14·2 answers
  • To reposition the legend to the left-hand side of a chart, click the _________ button, point to legend, click the right arrow ic
    7·1 answer
  • _____ is a higher-level, object-oriented application interface used to access remote database servers
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!