Hello
I am trying to make a program that can do addition and multiplication on super high numbers. What I have been doing is making an array and putting a digit in each element of the array. But I am haveing trouble when the digits equal more than ten.
this is my code so far.
I have three prints at the end for debugging purposes.Code:#include <stdio.h> int main() { int adarray[90][3]; int a;/* digit number */ int b;/* number manipulation interger */ int d = 0;/* number manipulation interger */ int c = 0;/* initialized first/second number */ for ( b = 0; b < 3; b++ ) { for ( a = 0; a < 90; a++ ) { adarray[a][b] = 0; /* Set each element to zero */ } } for ( b = 2; !b == 0 ; b-- ) { for ( a = 89; a > 70; a-- ) { c = c + 1; if ( c == 10 ) { c = 0; } adarray[a][b] = c; /* Set the first 20 of first and second numbers */ } } for ( a = 89; a > 0 ; a-- ) { adarray[a][0] = adarray[a][2] + adarray[a][1]; while ( adarray[a][0] >= 10 ) { d = a - 1; adarray[a][0] = adarray[a][0] - 10; adarray[d][0] = adarray[d][0] + 1;/* trouble is just here */ } } for ( a = 0; a < 90; a++ ) { printf( "%d", adarray[a][2] ); } printf( "\n" ); for ( a = 0; a < 90; a++ ) { printf( "%d", adarray[a][1] ); } printf( "\n" ); for ( a = 0; a < 90; a++ ) { printf( "%d", adarray[a][0] ); } }
The first 2 loops work OK and the first part of the third loop. What happens is all the elements get set to zero, then on the digits on the far right of the first 2 element groups get set to something. So far it all works, then it adds the first 2 element groups together in the third element group. Then the program checks to see if the elements in the third group are are over ten. If they are it takes off ten, then it is supposed to add one to the next element along.
For some reason it takes off the ten but does not add the one to the next element.
Can anyone tell me why, it is driving me crazy.
Thanks in advance.