| | |
Problem add and sub two big integer numbers in c++
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2008
Posts: 3
Reputation:
Solved Threads: 0
Write a program to add or subtract two big integer numbers. “Big” refers to a number which is more than 30 digits. You can assume that the number may have MAXIMUM 100 digits. Your program should have the data structures to hold such a big number. Also it should have two functions viz Add and Subtract and a main function which demonstrates the usage of Add and Subtract.
e.g of one such operation 12334444446666666666888888812233 + 2222227889999999999 = 12334444446668888894778888812232...
can anyone help me how to solve this problem or how to approach this problem...
its urgent if any sample code or any related url so plz forward it...
Thanks in Advance..
Prashnat
e.g of one such operation 12334444446666666666888888812233 + 2222227889999999999 = 12334444446668888894778888812232...
can anyone help me how to solve this problem or how to approach this problem...
its urgent if any sample code or any related url so plz forward it...
Thanks in Advance..
Prashnat
•
•
Join Date: Feb 2008
Posts: 7
Reputation:
Solved Threads: 1
make a fuction out of this program and brint to use
C++ Syntax (Toggle Plain Text)
#include<iostream> #include<string> using namespace std; int main() { int l1,k=0, i, l2,j,p; char s_num1[110], s_num2[110], s_ans[111]; int tens=0, ones, ans; cin>>s_num1; cin>>s_num2; //cout<<(int) s_num1[0]; for(l1=0;s_num1[l1]!='\0';l1++); for(l2=0;s_num2[l2]!='\0';l2++); l1--; l2--; for(i=l1, j = l2;(i>=0)&&(j>=0);i--,j--){ ans = (int) s_num1[i] + (int) s_num2[j] + tens - 2*48; ones=ans%10; tens=ans/10; s_ans[k] = ones + 48; k++; } while(i>=0){ cout<<"str 1 bigger\n"; ans = tens + (int) s_num1[i] -48; ones=ans%10; tens=ans/10; s_ans[k] = ones + 48; k++; i--; } while(j>=0){ cout<<"str2 biigger\n"; ans = tens + (int) s_num2[j] -48; ones=ans%10; tens=ans/10; s_ans[k] = ones + 48; k++; j--; } if(tens!=0) s_ans[k++] = tens+48; cout<<k<<endl; for(p=k-1;p>=0;p--) cout<<s_ans[p]; return 0; }
![]() |
Similar Threads
- Ordering an array (Java)
- Factorial of any length (C++)
- How to average a series of integers? (Assembly)
- getting data from a text file and putting it in an excel file using visual basic 6.0 (Visual Basic 4 / 5 / 6)
- Newbie question (C)
Other Threads in the C++ Forum
- Previous Thread: Problem with iterator
- Next Thread: Convert object of type string to a string
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator getline graph homeworkhelper iamthwee ifstream image input int integer java lib list loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings struct template text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





