My operating system : Windows 64 bit
Under codeblocks : When I go to Settings -> Compiler -> The selected compiler is "GNU GCC Compiler"
But , under the tab toolchain executables
I see the following information :
Compiler's Installation directory : C:\Program Files (x86)\CodeBlocks\MinGW
C compiler : mingw32-gcc.exe
C++ compiler : mingw32-g++.exe
I am trying to run the following C++ program :
#include<iostream>
#include<math.h>
using namespace std;
int find_size(int a,int b)
{
int lena=0;
int lenb=0;
while(a>1)
{
lena++;
a/=10;
}
while(b>1)
{
lenb++;
b/=10;
}
if(lena%2!=0)
lena+=1;
if(lenb%2!=0)
lenb+=1;
return (lena>lenb?lena:lenb);
}
int karatsuba (int x , int y)
{
if(x<=10 && y<=10)
return x*y;
int n=find_size(x,y);
int p1 = pow(10,n/2);
int p2 = pow (10,n);
int a = x/p1;
int b = x%p1;
int c = y/p1;
int d = y%p1;
int pdt = p2*karatsuba(a,c)+p1*(karatsuba(a,d)+karatsuba(b,c))+karatsuba(b,d);
return pdt;
}
int main()
{
int x,y;
cout<<"Enter the numbers"<<endl;
cin>>x>>y;
int ans=karatsuba(x,y);
cout<<"\n Product : "<<ans<<endl;
return 0;
}
The same code when run on an online compiler , gives me the correct output . But , codeblocs gives me a different output . What could be the issue with my compiler ? The same problem with my local Visual Studio code . It gives the same wrong output.
Example : Inputs , x =2023 , y=3003
Correct answer(And the output of online compiler) : 6075069
But My codeblocks' and VSC's output : 6132081
I have no idea what is wrong with my Codeblocks, VSC or my compiler . I've been using the same codeblocks for years and I have never encountered such a problem .
One information I can provide is that a few weeks back I installed MinGW , could that have caused a problem with my compiler settings ?
Can someone please help me rectify this problem ?