#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector <int> int1;
vector <int> int2;
vector <int> final;
int input1, input2;
int length = 0, length1 = 0;
cin >> input1 >> input2;
cout << "after cin" << endl;
string strNum = to_string(input1); // 123 becomes "123"
length = strNum.length(); // length = 3
string strNum1 = to_string(input2); // 123 becomes "123"
length1 = strNum.length(); // length = 3
if(length > length1){
strNum = to_string(input1); // 123 becomes "123"
length = strNum.length(); // length = 3
} else {
strNum1 = to_string(input2); // 123 becomes "123"
length1 = strNum.length(); // length = 3
}
cout << length;
string q = to_string(input2); // 123 becomes "123"
for(int i = 0; i < length; i++){
int1[i] = strNum.at(i);
int2[i] = strNum1.at(i);
}
cout << "after ye" << endl;
for(int i = 0; i < length; i++){
cout << " " << int1[i];
}
return 0;
}
Type Name Bytes Other Names Range of Values int 4 signed –2,147,483,648 to 2,147,483,647
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int asciiToInt(char ch)
{
return (ch - '0');
}
int main()
{
vector<int> largeInt1(12, 0); // initialize to zero
vector<int> largeInt2(12, 0); // initialize to zero
vector<int> finalInt(13, 0); // initialize to zero
// Loop four times
for (int i = 1; i <= 8; i++)
{
// Create a string variable for the input and the vectorIndex and finalIntIndex will be used for assigning each number in the proper position in the vectors
string number;
int vectorIndex = 11, finalIntIndex = 12;
cin >> number;
// Check that the number's length is not longer than the elements in the vector
if (number.length() > largeInt1.size())
{
cout << "That number is too large. Please try again" << endl;
i -= 1;
continue;
}
// If i is even, meaning we're getting input from the second or fourth number
if ((i % 2) == 0)
{
// Assign each character number to the element in the vector. Going from right to left for the vector and the number since you add right to left
for (int index = number.length() - 1; index >= 0; index--)
{
largeInt2[vectorIndex] = asciiToInt(number[index]);
vectorIndex -= 1;
}
// Since we're on the second or fourth number, start adding each vector together, starting from right to left
for (int index = largeInt1.size() - 1; index >= 0; index--, finalIntIndex--)
{
// Add the elements in largeInt1 and largeInt2 together at the same index in the current index for finalInt
finalInt[finalIntIndex] += largeInt1[index] + largeInt2[index];
// Check to see if that finalInt[finalIntIndex] is > 9 and we're not on the 0 index. If the number is then you need to subtract 10, storing the difference in the element one left of finalInt
if (finalInt[finalIntIndex] > 9 && index > 0)
{
}
}
// Print your answer, be sure to clear the vectors (set everything back to 0) so the next set of numbers are not being added on top of this set
}
// We're on the first or third input
else
{
// Assign each character number to the element in the vector. Going from right to left for the vector and the number since you add right to left
for (int index = number.length() - 1; index >= 0; index--)
{
largeInt1[vectorIndex] = asciiToInt(number[index]);
vectorIndex -= 1;
}
}
}
}
cin >> number; // assign the elements in the number to the elements in the first vector cin >> number; // assign the elements in the number to the element in the second vector
#include <iostream>
#include <vector>
#include <cctype>
#include <stdexcept>
#include <algorithm>
#include <numeric>
#include <string>
#include <functional>
#include <assert.h>
#include <sstream>
using namespace std;
int addition(string input1, string input2, int &result, vector<int> &largeInt1, vector<int> &largeInt2, vector<int> &finalInt);
int main() {
vector<int> largeInt1 (12, 0); // initialize to zero
vector<int> largeInt2 (12, 0); // initialize to zero
vector<int> finalInt (13, 0); // initialize to zeros
int result, flength;
string input1, input2, results;
cin >> input1;
cin >> input2;
for(int i = 0; i < input1.size(); i++) {
cout << input1.at(i);
}
for(int i = 0; i < input2.size(); i++) {
cout << input2.at(i);
}
largeInt1.resize(input1.size());
largeInt2.resize(input2.size());
flength = largeInt1.size()+largeInt2.size();
finalInt.resize(flength);
result = addition(input1, input2, result, largeInt1, largeInt2, finalInt);
stringstream convert;
convert << result;
results = convert.str();
cout << "String Conversion is: " << results << endl;
for (unsigned i=0; i<input1.length(); ++i)
{
finalInt[i] = input1.at(i);
}
for(int i = finalInt.size(); i <= 0; i--) {
cout << finalInt[i];
}
return 0;
}
int addition(string input1, string input2, int &result, vector<int> &largeInt1, vector<int> &largeInt2, vector<int> &finalInt){
int length, base, last, remainder;
bool isOdd;
for (int i=0; i<input1.length(); ++i)
{
largeInt1[i] = input1.at(i);
}
for (int i = 0; i<input2.length(); i++) {
largeInt2[i] = input2.at(i);
}
cout << "Input to LargeInt1: ";
for(int i = 0; i < largeInt1.size(); i++) {
cout << largeInt1[i] << " ";
cout << endl;
}
cout << endl;
cout << "Input to LargeInt2: ";
for(int i = 0; i < largeInt2.size(); i++) {
cout << largeInt2[i];
cout << endl;
}
cout << endl;
length = input1.size()+input2.size();
if((length & 1) == 0) {
} else {
isOdd = true;
}
last = largeInt1.size();
for(int i = 0; i <= length; i++) {
base = largeInt1[i]+largeInt2[i];
cout << "Base in << " << i << ": " << base << endl;
if(base >= 10) {
remainder = base-9;
finalInt[i] = base-remainder;
cout << "Remainder in << " << i << ": " << remainder << endl;
} else {
finalInt[i] = base;
}
}
cout << "Result is: " << result << endl;
return result;
}
for(int i = 0; i <= length; i++) {
remainder = base-9;
finalInt[i] = base-remainder;
al·go·rithm
ˈalɡəˌriT͟Həm/
noun
noun: algorithm; plural noun: algorithms
a process or set of rules to be followed in calculations or other problem-solving operations, especially by a computer.
mpz_set_str (MP_INT *integer, char *initial_value, int base)
std::string add_it( char const * in1, char const * in2, int const SIZE)
{
MP_INT integ1, integ2, result;
mpz_set_str (&integ1, in2, 10);
mpz_set_str (&integ2, in2, 10);
mpz_add (&result, &integ1, &integ2);
char output[SIZE];
mpz_get_str (output, 10, &result);
return output;
}
#include <iostream>
#include <vector>
#include <cctype>
#include <stdexcept>
#include <algorithm>
#include <numeric>
#include <string>
#include <functional>
#include <assert.h>
#include <sstream>
using namespace std;
int addition(string input1, string input2, int &result, vector<int> &largeInt1, vector<int> &largeInt2, vector<int> &finalInt);
int main() {
vector<int> largeInt1 (12, 0); // initialize to zero
vector<int> largeInt2 (12, 0); // initialize to zero
vector<int> finalInt (13, 0); // initialize to zeros
int result, flength;
string input1, input2, results;
cin >> input1;
cin >> input2;
for(int i = 0; i < input1.size(); i++) {
cout << input1.at(i);
}
for(int i = 0; i < input2.size(); i++) {
cout << input2.at(i);
}
largeInt1.resize(input1.size());
largeInt2.resize(input2.size());
flength = largeInt1.size()+largeInt2.size();
finalInt.resize(flength);
result = addition(input1, input2, result, largeInt1, largeInt2, finalInt);
stringstream convert;
convert << result;
results = convert.str();
cout << "String Conversion is: " << results << endl;
for (unsigned i=0; i<input1.length(); ++i)
{
finalInt[i] = input1.at(i);
}
for(int i = finalInt.size(); i <= 0; i--) {
cout << finalInt[i];
}
cin >> flength;
return 0;
}
int addition(string input1, string input2, int &result, vector<int> &largeInt1, vector<int> &largeInt2, vector<int> &finalInt){
int length, base, last, remainder;
bool isOdd;
for (int i=0; i<input1.length(); ++i)
{
for(int n = 0; n < 12; n++) {
if(input1.at(i)%(n+1)*10 == input1.at(i)) {
largeInt1[12-n] = input1.at(i);
}
}
}
for (int i = 0; i<input2.length(); i++) {
for(int n = 0; n < 12; n++) {
if(input2.at(i)%(n+1)*10 == input2.at(i)) {
largeInt2[12-n] = input2.at(i);
}
}
}
cout << "Input to LargeInt1: ";
for(int i = 0; i < largeInt1.size(); i++) {
cout << largeInt1[i] << " ";
cout << endl;
}
cout << endl;
cout << "Input to LargeInt2: ";
for(int i = 0; i < largeInt2.size(); i++) {
cout << largeInt2[i];
cout << endl;
}
cout << endl;
length = input1.size()+input2.size();
if((length & 1) == 0) {
} else {
isOdd = true;
}
last = largeInt1.size();
for(int i = 0; i <= length; i++) {
base = largeInt1[12-i]+largeInt2[12-i];
cout << "Base in << " << i << ": " << base << endl;
if(base >= 10) {
remainder = base-9;
finalInt[12-i] = base-remainder;
cout << "Remainder in << " << i << ": " << remainder << endl;
} else {
finalInt[12-i] = base;
}
}
cout << "Result is: " << result << endl;
return result;
}