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]
2 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]2 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
Press the _______ key to move to the next cell in a row.
slamgirl [31]

Tab is the answer! And it says i need 20 chacters to explain so im writing random stuffff



4 0
3 years ago
___________ is a computer processor which incorporates the functions of a computer's central processing unit (CPU) on a single i
Yanka [14]

Answer:

Microprocessor

Explanation:

A microprocessor is a programmable chip that incorporates in itself the functions of a computer's central processing unit. It contains millions of small components such as transistors and resistors. In fact, the microprocessor is sometimes called the CPU itself as it contains an Arithmetic Logic Unit(ALU), a control unit and register array.

They work at a very high speed due to the components that they contain and are available at relatively low cost. They are portable, reliable and compared to vacuum tubes, they generate less heat.

<em>Hope this helps!</em>

6 0
3 years ago
Read 2 more answers
What is the primary way to access applications in window 10
Alex787 [66]

Choose Start, type the name of the application, like Word or Excel, in the Search programs and files box. In the search results, click the application to start it. Choose Start > All Programs to see a list of all your applications. You might need to scroll down to see the Microsoft Office group.

8 0
3 years ago
The alumni development office at your university uses specialized software that can be accessed from two different servers. The
Agata [3.3K]

Answer:

Round-Robin DNS

Explanation:

According to my experience in Information Technology and Networking it can be said that based on the information provided the best solution would be to set up a Round-Robin DNS. This term refers to a technique used to balance the load on a server, where a client request is sent to each server one at a time, and then the system repeats the process from the top of the request list. This prevents the server from being drowned in a sea of simultaneous requests.

If you have any more questions feel free to ask away at Brainly.

6 0
3 years ago
In addition to key executives, there are other positions in a company that may be considered critical, or whose loss will be dif
Otrada [13]

Answer:

Explanation:

Every employee who works for a company plays an important role in his field. some of the key employees of a company is sales representative, marketing executives, human resource managers, etc

whereas in manufacturing sector additional employees are developers, manufacturing workers, quality testers, etc, which when leaves a company, there is always a chance for the employee to join the competitors which is a threat to integrity of a company

Plus particular field becomes unstable for that time until a good employee hire again for the same position.

If a network administrator leaves, the company may suffer from their network issues. as a network administrator maintain networks, troubleshoot with any network problem, checks the security of the network and many more, he plays a very important role in the company.

If a sales representative leaves the job from the company, sometimes it results as a great loss of a company as a sales representative is in direct contact with customers, and when they leave a job there are chances that they carry the customer with them which results in loss of business.

5 0
2 years ago
Other questions:
  • . One of the vulnerabilities the Morris worm used was a networking service called finger. The purpose of the finger service is t
    11·1 answer
  • TRUE OR FALSE! HELP!!
    13·1 answer
  • When replacing a thermostat or water pump, coolant drained from the cooling system should be ________.
    9·1 answer
  • How to delete Brainly account ?​
    12·1 answer
  • In this exercise, you will get some practice with the __add__ method by implementing it for a class called ContactBook. This cla
    12·1 answer
  • What statement best describes entrepreneurship?
    7·2 answers
  • What does the following loop do? val = 0 total = 0 while (val &lt; 10): val = val + 1 total = total + val print(total)
    15·1 answer
  • What is Japanese tradition?
    8·2 answers
  • 7.4 Lesson Practice (projectstem): what is output if the user is enters 2?​
    8·1 answer
  • 2.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!