Okay, so i have an idea...that looks like it should work. I'm supposed to be able to multiply for example: 1234567812345678912345678*1234562345673456.
My idea was to put each number into a string, and then make a matrix to store the values of each digit multiplied by each digit... i'll put an image down there so you could see what i mean. I've done all of that, but the tricky part comes now.. i gotta sum the diagonals of that table (red ones on the pic)... put the sums into another array, and then work with fixing numbers larger than 9 in them. Hope someone got what i was thinking... Just tell me if it's a stupid idea!
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#define MAX 505
using namespace std;
int fix(char a[MAX], char b[MAX]){while(strlen(a) != strlen(b))
if(strlen(a) < strlen(b))
{strrev(a); strcat(a, "0"); strrev(a);}
else {strrev(b); strcat(b, "0"); strrev(b);}
}
int main(void)
{
char n1[MAX], n2[MAX];
scanf("%s%s", n1, n2);
fix(n1, n2);
//printf("%s %s", n1, n2);
int mat[MAX][MAX], bigarr[2*MAX];
for(int i = 0; i < strlen(n1); i++)
for(int j = 0; j < strlen(n2); j++){
mat[i][j] = (int(n1[i])-48)*(int(n2[j])-48);
//printf("%d", mat[i][j]);
}
scanf("\n");
return 0;
}
ow, and also, if someone could tell me an easier way to concatenate a string to add some zeros to it, i would be really thankful. <--- this is the image