+ 4
Please guide me to final output. I'm stuck in a part where it should return 1 if i enter negetive arg or zero
* function named "reduce". * takes 2 pos+ integer arguments called num and denom, treats them as the numerator and denominator of a fraction, and reduces the fraction. *each of the two arguments must be modified by dividing it by the greatest common divisor of the integers. *function should return 0 to indicate failure to reduce or negative, and return 1 if it one of arguments is neg- or zero https://code.sololearn.com/cnp3w7z5s5J5/?ref=app
4 Réponses
+ 2
Thanks to you @Gordie and @Kinshuk Vasisht👍
Here is a rectified code of which I used your data into it and perfectly works fine now.
https://code.sololearn.com/c93CV12B3jmb/?ref=app
+ 1
I am unable to understand your query. Can you explain in more detail?
If its about designing the reduce function, then I noticed that in your code you have not added conditionals to verify if the reduction failed or if the arguments were invalid.
So, you may try the following function instead :
int reduce(int a, int b)
{
if(a<=0||b<=0) return 1;
// If args are invalid, return 1.
num = a/gComDivisor(a,b);
denom = b/gComDivisor(a,b);
if(gComDivisor(a,b)==1)
return 0;
// If the reduction fails due to
// GCD = 1, return 0.
cout<<num<<"/"<<denom<<endl;
return 2;
// Else, if we succeed, return 2.
// or any number != 0 or 1.
}
+ 1
@Gordie Thanks..I'm short of words & that's the reason I chose to have something I have done & with the explanations you have provoded ..I now have an idea to where to start next time..Thanks again for explaining such to me.👌