mercredi 26 juillet 2017

Odd APPCRASH error in GCD program?

using namespace std;
#include <iostream>
int GCD(int a, int b){
    while(b!=0){
        int temp=b;
        b=a%b;
        a=temp;
    }
    return a;
}
int main(){
    int a=0, b=0;
    cout<<"Please enter two integers to find their GCD using the Euclidean algorithm.";
    cin>>a>>b;
    cout<<"The greatest common divisor of "<<a<<" and "<<b<<" is "<<GCD(a,b)<<".";
}

This is a simple C++ program that finds the greatest common divisor of two numbers, and it runs just fine. However, if I change

int GCD(int a, int b){
    while(b!=0){

into while(a!=0){, I experience an APPCRASH error, exception code c0000094 that kills my run. I am running C++11 ISO standards and my IDE is Code::Blocks 16. I am pretty new to C++ and this site, so please correct me if my coding format, logic or even question posting etiquette is incorrect in any way.

Thanks a ton!

Aucun commentaire:

Enregistrer un commentaire