#include <stdio.h>?
#include <stdlib.h>?
#include <string.h>?
#define MAXLEN (100)?
#define RSTMAX (1000000)?
int main(int ac,char **av)? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
{?
? ? char Mp1[MAXLEN] = {0},Mp2[MAXLEN] = {0};??
? ? char temp[MAXLEN + 3] = {0},rst[RSTMAX] = {0};?
? ? int? i = 0,j = 0,t = 0,s = 0;?
? ? int? len1 = 0,len2 = 0;?
? ? int? bit = 0;?
??
? ? printf("============= Welcome to Mutip Calculate ============n");?
? ? printf("Please enter two number you want to calculate : n");?
? ? scanf("%s%s",Mp1,Mp2);?
? ? len1 = strlen(Mp1);?
? ? len2 = strlen(Mp2);?
? ? for(j = len2 - 1; j >=0; --j){?
? ? ? for(i = len1 - 1,t = len1; i >= 0; --i,--t){?
? ? ? ? ? // let two number not two character to multiply?
? ? ? ? ? temp[t] = (Mp1[i] - 0x30) * (Mp2[j] - 0x30);??
? ? ? ? ? // 0x30 == 48 == '0'?
? ? ? }? ? ? ??? ? ? ? ?
? ? ? // adjust temp's each bit number which more than 9 to between 0 to 9?
? ? ? for(t = len1; t >0; --t){?
? ? ? ? ? if(temp[t] > 9){?
? ? ? ? ? ? ? temp[t-1] += temp[t]/10;?
? ? ? ? ? ? ? temp[t] %= 10;?
? ? ? ? ? }?
? ? ? }?
??
? ? ? // sum the new result to the original result;? ? ? ??
? ? ? for(s = len1 + len2 - bit,t = len1; t >= 0; --s,--t){?
? ? ? ? ? rst[s] += temp[t];?
? ? ? }?
??
? ? ? // ajust the new result which more than 9? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
? ? ? for(s = len1 + len2; s > 0; --s){?
? ? ? ? ? ? if(rst[s] > 9){?
? ? ? ? ? ? ? ? rst[s-1] += rst[s]/10;?
? ? ? ? ? ? ? ? rst[s] %= 10;?
? ? ? ? ? ? }?
? ? ? ? }?
??
? ? ? ? // bzero the temp array?
? ? ? ? for(t = len1; t >= 0; --t){?
? ? ? ? ? ? temp[t] = 0;?
? ? ? ? }?
? ? ? ? bit++;?
? ? }?
? ? ??
? ? // in order to narmal output the result as a string not a interge?
? ? rst[len1 + len2 + 1] = ' ';?
? ? ??
? ? // switch rst's each bit to character save into the result array.?
? ? for(s = 0; s <= len1 + len2; ++s){?
? ? ? ? rst[s] += 0x30;?
? ? }?
??
? ? // delete the first zero before output the result.? ??
? ? for(s = 0; s < len1 + len2; ++s){?
? ? ? ? if(0x30 == rst[0]){?
? ? ? ? ? ? for(t = 0; t <= len1 + len2 - s; ++t){?
? ? ? ? ? ? ? ? rst[t] = rst[t+1];?
? ? ? ? ? ? }? ??
? ? ? ? }else{?
? ? ? ? ? ? break;?
? ? ? ? }?
? ? }?
??
? ? // output the result;?
? ? printf("%s * %s = %sn",Mp2,rst);?
? ? printf("========== Bye Bye ==========n");?
? ? return 0;?
}