topics

全部话题 - 话题: getgcd
(共0页)
a****m
发帖数: 693
1
#include
using namespace std;
class CFraction
{
public: //public method to get GCD
int iNumerator;
int iDenominator;
double dValue;
//constructor...
CFraction( int iNumeratorParam, int iDenominatorParam )
{
iNumerator = iNumeratorParam;
iDenominator = iDenominatorParam;
dValue = iNumerator/ iDenominator;
}
//getGCD
int getGCD( int iNumerator, int iDenominator )
{
int remainder = iDenominator % iNumerator;
if ( remainder != 0 )
return getGCD( remainder,iNumerator );
}
//Reduce (wha... 阅读全帖
a****m
发帖数: 693
2
#include
#include "GCD.hpp"
using namespace std;
class CFraction
{
public: //private method to get GCD
int iNumerator;
int iDenominator;
//constructor...
CFraction( int iNumeratorParam, int iDenominatorParam )
{
iNumerator = iNumeratorParam;
iDenominator = iDenominatorParam;
}
//getGCD
int getGCD( int iNumerator, int iDenominator )
{
int remainder = iDenominator % iNumerator;
if ( remainder != 0 )
return getGCD( remainder,iNumerator );
else return 0;
}
CFraction reduce()
{
int iGC... 阅读全帖
s***a
发帖数: 299
3
//getGCD
int getGCD( int iNumerator, int iDenominator )
{
int remainder = iDenominator % iNumerator;
if ( remainder != 0 )
return getGCD( remainder,iNumerator );
// I think you must add else here since you must return an int here
}
a****m
发帖数: 693
4
CFraction reduce()
{
int iGCD = getGCD(int iNumerator, int iDenominator);
// 总是在这一行出问题: expected primary-expression before "int"
//It seems that it does not need redefine the type, getGCD(inum, idenom)
iNumerator=iNumerator/iGCD;
iDenominator=iDenominator/iGCD;
}
thanks all you guys!
t****t
发帖数: 6806
5
int iGCD = getGCD(int iNumerator, int iDenominator);
哦, 这一行啊, 你看你写的是什么呀? copy/paste也不能这样啊.
c**b
发帖数: 2999
6
1.這個函数有返回值吗? 没看见里面有return;
2.int iGCD = getGCD(iNumerator,iDenominator);
(共0页)