From e9cae065ea72d1fa0ddab1cc850d974752885cac Mon Sep 17 00:00:00 2001 From: Tanya Singh Date: Sun, 17 Oct 2021 14:27:01 +0530 Subject: [PATCH] Updated large_sum.cpp --- large_sum.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/large_sum.cpp b/large_sum.cpp index 025a3b2..9aec738 100644 --- a/large_sum.cpp +++ b/large_sum.cpp @@ -153,4 +153,61 @@ int main() s2.pop(); } -} \ No newline at end of file +} + +//using stack.h +#include +using namespace std; +#include "stack.h" +void add(Stack s); + +int main() +{ + Stack s1; + int n, m; + cout<<"Enter total digits in 1st number: "; + cin>>n; + cout<<"Enter the digits of 1st number: "; + for(int i=0; i>m; + s1.push(m); + } + add(s1); + + return 0; +} + +void add(Stack s1) +{ + Stack s2; + Stack s3; + int n2, m2, ele = 0, temp = 0, carry = 0; + cout<<"Enter total digits in 2nd number: "; + cin>>n2; + cout<<"Enter the digits of 2nd number: "; + for(int i=0; i>m2; + s2.push(m2); + } + + while(s1.is_empty() != 0 && s2.is_empty() != 0) + { + temp = s1.top_ele() + s2.top_ele() + carry; + ele = temp%10; + s3.push(ele); + carry = temp/10; + s1.pop(); + s2.pop(); + } + if(s1.is_empty() == 0 && s2.is_empty() == 0) + { + s3.push(carry); + } + + + cout<<"\nSum = "; + s3.display(); + cout<