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 best prediction she could make about this
densk [106]

Answer:its a play

Explanation:

6 0
3 years ago
Read 2 more answers
Question B_1 (15 points) Please define (describe) local variables and how they are used in computer programming ( e.g. In C, C )
OverLord2011 [107]

Answer and Explanation:

Static variables are variables that still maintain their values outside the score which they are declared. They are declared with the static keyword

Example:

<em>static int score = 30;</em>

Local variables are variables whose scope are restricted to a block. Their values are restricted to the block which they are declared in.

Example:

<em>void abd(){</em>

<em>int score;</em>

<em>}</em>

<em>score is a local variable to abcd() function</em>

5 0
3 years ago
A cell reference =SUM(sheet1.A1,sheet 2.A2) will place the results in which of the following, the current worksheet, worksheet 1
kozerog [31]

Answer:

the current worksheet

Explanation:

However, the syntax mentioned is incorrect. It should be

=SUM(sheet1!A1,sheet2!A2)

The above is the correct syntax, And this will print the sum in the sheet that we are in currently. And hence, the correct option for this question is certainly the current worksheet. Hence, the option mentioned in the answer section is the correct one.

3 0
4 years ago
Which character is cannot be used in a file name _ (underscore)/ (backslash)- (hyphen) % ( percent)
Crazy boy [7]
In Windows a (real) backslash is a path separator. The % is involved with DOS variables.
4 0
3 years ago
What are three ways of verifying legitimate right of access to a computer system?
dezoksy [38]

Something you know (such as a password)

Something you have (such as a smart card)

Something you are (such as a fingerprint or other biometric method)

<h3>What are the 3 methods of authentication?</h3>
  • The three authentication factors are Knowledge Factor – something you know, e.g. password.
  • Possession Factor – something you have, e.g.mobile phone. Inherence Factor – something you are, e.g., fingerprint.

To learn more about it, refer

to brainly.com/question/22654163

#SPJ4

7 0
2 years ago
Other questions:
  • Continuous reboots of a Windows host upon encountering a persistent stop error might be caused by Startup and Recovery configura
    10·1 answer
  • gAssume that you are writing a program to merge two files named FallStudents and SpringStudents. Each file contains a list of st
    15·1 answer
  • Which statement is most likely to be true about a computer network?
    11·2 answers
  • how do i create an advanced search using the search criteria in the range K2:S3 and the inventory data where the results will be
    8·1 answer
  • An objective function in linearprogramming is a(n):
    11·1 answer
  • To display the entire entry for a calculated field, select the column in the Field row, right-click to display the shortcut menu
    15·1 answer
  • When light does not pass through or bounce off an object, it is said to be
    13·2 answers
  • What is the output of the following code<br> X = 06<br> y = 0<br> print (x ** y)
    12·1 answer
  • Join for a pack battle loud microphone.
    10·1 answer
  • Suppose that you have been asked to create an information system for a manufacturing plant that produces nuts and bolts of many
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!