Bull Math-Large Number Multiplication

Bulls are much better than cows in mathematics. They can multiply huge integers and get completely precise answers...or so they say. Farmer John wants to know if their answer is correct. Help him check the Bulls' answer. Read two positive integers (with no more than 40 bits each) and calculate their product. Output it as a normal number (no extra leading zeros).

FJ requires you to do this yourself; do not use special library functions for multiplication.
Input value
* Line 1...2: Each line contains a decimal number.
Output volume
* Line 1: The exact product of the two input lines
Sample input
11111111111111
1111111111
Sample output
12345679011110987654321

#include<stdio.h>
#include<string.h>
int main()
{
    
    
	char aa[50],bb[50];
	int s[100]={
    
    0},i,j,f=0,k,l1,l2,x,y,z,a[50],b[50];
	scanf("%s%s",aa,bb);
	l1=strlen(aa),l2=strlen(bb);
	for(i=l1-1,j=0;i>=0;i--)
	a[j++]=aa[i]-'0';
	for(i=l2-1,j=0;i>=0;i--)
	b[j++]=bb[i]-'0';
	for(i=0;i<l2;i++)
	{
    
    
		f=0;
		k=i;x=0,y=0;
		for(j=0;j<l1;j++)
	   {
    
    
		x=y+a[j]*b[i]+s[k];
		y=x/10;
		s[k]=x%10;
		k++;
	   }
	   if(y!=0)
	   f=1,s[k]=y;
	   /*for(int ii=k+f-1;ii>=0;ii--)
	  printf("%d",s[ii]);
	  printf("\n%d\n",k);*/
   }
	for(i=k+f-1;i>=0;i--)
	printf("%d",s[i]);
	printf("\n");
	return 0;
}

Guess you like

Origin blog.csdn.net/m0_46381590/article/details/112095283