Add Two Strings
Given two non-negative integers, represented as strings, return their sum as a string.
We'll cover the following...
Statement
Given two non-negative numbers as strings. Implement a function that takes these strings as input, performs the addition, and returns the output in the form of a string.
Example
We are given two non-negative integers, “11” and “123” represented as strings. The sum of the strings is “134”.
Sample input
num1 = "11", num2 = "123"
Expected output
"134"
Try it yourself
#include <iostream>#include <string>using namespace std;string AddStrings(string num1, string num2) {// TODO - Write your code herereturn "";}
Solution
We’ll use digit-by-digit addition to solve this problem because we cannot convert the strings to integers. The algorithm for decimal addition is given ...
Access this course and 1400+ top-rated courses and projects.