C++ Multiply 2 Overflow Numbers

Download an eBook today

This program will allow you to input 2 large numbers and multiple them using C++


   *Featured code submitted and Created by 🇻🇳GNAOH🇻🇳.


C++


#include <iostream>
#include <cstring>
using namespace std;
char n1[100],n2[100];int r[200];
int main()
{
    int n;
    cin>>n1>>n2;cout<<"  "<<n1<<" * "<<n2<<endl<<"= ";
    strrev(n1);strrev(n2);
    for(int i=0;i<strlen(n2);i++)
    {
        for(int j=0;j<strlen(n1);j++)
        {
            n=(n1[j]-48)*(n2[i]-48);
            r[i+j]+=n;
            if(r[i+j]>=10)
            {
                r[i+j+1]+=r[i+j]/10;
                r[j+i]=r[i+j]%10;
            }
        }
    }
    for(int i = strlen(n1) + strlen(n2) - 1 ; i >= 0;i--)
    {
        if(i==strlen(n1) + strlen(n2) - 1 && r[i]==0)
            continue;
        cout<<r[i];
    }
}


Click here to run this code



More Free Code Examples:


C++ Code to Reverse a Number


C++ Odd or Even


C++ Code to Reverse a String







Comments

Popular posts from this blog