1. ## Arithmetic exception

Hi The following is my code I am getting Arithmetic exception in gcd function at rem=a%b can anyone help me finf why? how do I fix it?

Code:
```#include "Pionare.h"

int main(int argc, char * argv[]) {
int  n=atoi(argv[1]);// convert string to integer
Pionare Pionare1(n);
return 0;
}

Pionare::Pionare(int n)
{
cout << "am in cons";
this->n=n;
cout << "n is" << n;
Findab();
}

void Pionare::Findab(){
cout << "n is" << n;
for(b=1;b<=n;b++){
for(a=1;a<= b*1.414;a++){
cout << "am here";
if(Gcd(a,b)==1){

p=a*a*a*a-6*a*a*b*b+b*b*b*b;

q=(a*a+b*b)*(a*a+b*b);
B=-54*(p*p*p*p*p*p-33*p*p*p*p*q*q-33*p*p*q*q*q*q+q*q*q*q*q*q);
A=-27*(p*p*p*p+14*p*p*q*q+q*q*q*q);

//output to file
}
}
}
}

int Pionare::Gcd(int a,int b){
int rem;
cout<<a<<endl<<b<<endl;
while (a !=0)

{
rem = a % b;

a= b;

b = rem;
}

return (a);
}```

2. a%b should only cause a fuss if b is 0.

3. Or perhaps if a or b is negative??

4. Code:
```void Pionare::Findab(){
cout << "n is" << n;
for(b=1;b<=n;b++){
for(a=1;a<= b*1.414;a++){
cout << "am here";
if(Gcd(a,b)==1){

p=a*a*a*a-6*a*a*b*b+b*b*b*b;

q=(a*a+b*b)*(a*a+b*b);
B=-54*(p*p*p*p*p*p-33*p*p*p*p*q*q-33*p*p*q*q*q*q+q*q*q*q*q*q);
A=-27*(p*p*p*p+14*p*p*q*q+q*q*q*q);

//output to file
}
}
}
}```
How are a and b defined on this scope? Ints? Doubles? In order to leverage your multiplication, they should be doubles (or floats).

Todd

5. Originally Posted by Todd Burch
Or perhaps if a or b is negative??
Division is still defined for negative numbers. -7%-2 is -1; 7%-2 is 1.

% is only defined for integers, so a and b are integers. There's not anything wrong with a <= b*1.414; everything will get promoted to double and everyone's happy. I mean, how else are you going to represent sqrt(2) without having it evaluated each time?

I suppose I should mention that your Gcd function, while interesting, will by necessity always return 0. Try while (b!=0).

6. Code:
```int Pionare::Gcd(int a,int b)
{
int rem;
cout<<a<<endl<<b<<endl;
while (a !=0)
{
rem = a % b;

a= b;

b = rem;
}

return (a);
}```