You'll be given two intergers. The number of the digits of each is from 1 to 200, inclusive.
And what you need to do is to culcalate the product of the two intergers.
The number of the digits of the product won't be more than 400.
Input format:
Two lines in total.
The first line is an interger a(0 <= a < 10200), and the second line is an interger b(0 <= b < 10200).
Output format:
Only one line, which is the product of a and b.
Sample input:
12
2
Sample output:
24
- #include<stdio.h>
- #include<string.h>
- int multiplication(char*a,char*b,int*c);
- int main(){
- int c[400+10], i;
- int k;
- char a[200+10]={0};
- char b[200+10]={0};
- memset(c,0,sizeof(c));
- gets(a);
- gets(b);
- if((a[0]=='0')||(b[0]=='0')){
- printf("0\n");
- }else{
- k = multiplication(a, b, c);
- for(i = k; i >=1; i--) printf("%d", c[i]);
- printf("\n");
- }
- return0;
- }
- int multiplication(char*a,char*b,int*c){
- int i, j, m, tem, k =405, la, lb;
- la = strlen(a);
- lb = strlen(b);
- for(i = lb -1; i >=0; i--){
- for(j = la -1, m =0; j >=0; j--){
- tem = c[(lb-i)+(la-j)-1];
- c[(lb-i)+(la-j)-1]=
- ((a[j]-'0')*(b[i]-'0')+ m + c[(lb - i)+(la - j)-1])%10;
- m =((a[j]-'0')*(b[i]-'0')+ m + tem)/10;
- }
- c[(lb-i)+(la-j)-1]= m;
- }
- while(!c[k]) k--;
- return k;
- }