//Progam to perform multiplication of 2 huge positive numbers
#include<iostream>
using namespace std;
#include<conio.h>
//#include<string>
//Functions to typecast from integer to character and vice versa
char ntoc(int n){ return char(n)+48;}
int cton(char c){ return int(c)-48;}

//Global array to store the result
char s[20000];

//Function to trim the preceding zeroes from the result
void display(char s1[]){
     int j=0,flag=0;
     while(s1[j]=='0')j++;
     for(int i = j;i<20000;i++){
                               cout<<s1[i];
                               flag=1;
     }
     //The case when one of the number is zero
     if(!flag)cout<<0;
}

//Function to add 2 very very long numbers
int add2strings(char s1[],char s2[]){

    int size=20000,carry=0;
    while(size--){
                   int temp=cton(s1[size])+cton(s2[size])+carry;
                   s[size] = ntoc(temp%10);
                   carry = temp/10;
                   }
}

//Function to move the block of numbers from left to right
//It helps in performing addition/mulitplication as we start from the right
void shift(char s1[]){
    int l=strlen(s1);
    for(int i =l;i>=0;i--){
                           s1[20000-(l-i)]=s1[i];
                           s1[i]='0';
            }
}

//Function to shift a string left by n places
void shiftleft(char s1[],int n){
    if(n==0) return;
    int l=strlen(s1);
    for(int i =n;i<20000;i++){
                              s1[i-n]=s1[i];
                              s1[i]='0';
    }

}

int main(){
    char s1[20000];
    char s2[20000];
    char tempo[20000];
    for(int i = 0;i<20000;i++){
                               s1[i]='0';
                               s2[i]='0';
                               s[i]='0';
            }
    
    cout<<"Enter First Number:";
    cin>>s1;
    cout<<"\nEnter Second Number:";
    cin>>s2;
    int l1=strlen(s1);
    int l2=strlen(s2);
    
    //Doing the shift as by default the characters are accumulated on the left side
    shift(s1);
    shift(s2);

  int n=-1;
  for(int i=20000-1;i>=20000-l2;i--)
  {                                 //Reseting temporary array
                                    for(int k = 0;k<20000;k++){
                                            tempo[k]='0';
                                    }
          
                                    int carry=0,lastindex=0;
                                    for(int j =20000-1;j>=20000-l1;j--){

                                          int temp = cton(s2[i])*cton(s1[j])+carry;
                                          carry = temp/10;
                                          tempo[j]= ntoc(temp%10);
                                          lastindex=j;
                  
                                    }
                                    if(carry)
                                           tempo[lastindex-1]=ntoc(carry);
                  
                                    n++;
                                    shiftleft(tempo,n);
                                    add2strings(tempo,s);
  }
  cout<<endl<<"Product is:";
  display(s);

  getch();
}

