Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- class BigInt {
- unsigned char *data;
- int bound;
- public:
- BigInt(){
- data = new unsigned char[1024];
- bound = 0;
- }
- ~BigInt(){
- delete [] data;
- }
- void setFromInt(int value){
- bound = 0;
- while(value>0){
- data[bound++] = value % 100;
- value /= 100;
- }
- }
- void print(){
- for(int i=bound-1;i>=0;i--){
- if(data[i]<10 && i!=bound-1){
- printf("0%i", data[i]);
- }else{
- printf("%i", data[i]);
- }
- }
- }
- void add(BigInt &other){
- int reminder = 0;
- int i;
- for(i=0;i<other.bound;i++){
- data[i] += other.data[i] + reminder;
- reminder = data[i]/100;
- data[i] %= 100;
- }
- while(reminder>0){
- data[i] += reminder;
- reminder = data[i]/100;
- data[i] %= 100;
- i++;
- }
- bound = i;
- }
- };
- int main(){
- BigInt a, b;
- a.setFromInt(1231231231);
- b.setFromInt(1434562345);
- a.print();
- printf("\n");
- b.print();
- printf("\n");
- a.add(b);
- a.print();
- printf("\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement