C ++代码包含错误

时间:2014-11-25 21:34:13

标签: c++ c++11

它不起作用,告诉我我犯的错误在哪里以及为什么它根本不起作用。对不起,我是C ++的新手。

#include<iostream>
#include<conio>
long gcd(long, long);

int main() {
    int m, n;
    cout << "enter the  1st integer =";
    cin>>m;
    out << "enter the  2nd integer =";
    cin>>n;
    cout << "gcd(" << m << " " << n << " )\n=";
    cout << gcd(m, n) << endl;
    getch();
}

long gcd(long m, long n) {
    while (n != 0) {
        long r = m % n;
        m = n;
        n = r;
    }
    return m;
}

1 个答案:

答案 0 :(得分:2)

你包括conio而不是conio.h你没有声明std ::或使用命名空间std而你的一个cout刚刚出来。您可能希望发布将来获得的错误并格式化代码。

#include<iostream>
#include<conio.h>
long gcd(long,long);

using namespace std;
int main()
{
    int m,n;
    cout<<"enter the  1st integer =";
    cin>>m;
    cout<<"enter the  2nd integer =";
    cin>>n;
    cout<<"gcd("<<m<<" "<<n<<" )\n=";
    cout<<gcd(m,n)<<endl;
    getch();
}
long gcd(long m,long n){
    while(n!=0){
        long r=m%n;
        m=n;
        n=r;
    }
    return m;
}