#include <stdio.h> #include <limits.h> // provides the constant INT_MAX #include
ID: 3554819 • Letter: #
Question
#include <stdio.h>
#include <limits.h> // provides the constant INT_MAX
#include <stdlib.h> // provides abs function and malloc
#include "Fraction.h"
int gcd(int a, int b)
{
if (a == 0 && b == 0) {
printf("Illegal args to gcd: %d, %d ",a,b);
exit(1);
}
a = abs(a);
b = abs(b);
if (a == 0)
return b;
if (b == 0)
return a;
return gcd(b,a%b);
}
Fraction string_to_fraction(const char *S)
{ // THIS CODE IS INCORRECT - FIX IT!
Fraction result = {0,1};
return result;
}
const char * fraction_to_string(Fraction R)
{ // THIS CODE IS INCORRECT - FIX IT!
const char * answer = malloc(1);
return answer;
}
int compare_fractions(Fraction L, Fraction R)
{
// THIS CODE IS INCORRECT - FIX IT! return 0;
}
void reduce_fraction(Fraction *R)
{ // THIS CODE IS INCORRECT - FIX IT!
}
Fraction add_fractions(Fraction L, Fraction R)
{ // THIS CODE IS INCORRECT - FIX IT!
Fraction result = {0,1};
return result;
}
Explanation / Answer
#include <stdio.h>
#include <limits.h> // provides the constant INT_MAX
#include <stdlib.h> // provides abs function and malloc
#include "Fraction.h"
int gcd(int a, int b)
{
if (a == 0 && b == 0) {
printf("Illegal args to gcd: %d, %d ",a,b);
exit(1);
}
a = abs(a);
b = abs(b);
if (a == 0)
return b;
if (b == 0)
return a;
return gcd(b,a%b);
}
int compare_fractions(Fraction L, Fraction R)
{
return compare_fractions;
}
void reduce_fraction(Fraction *R)
{
main()
}
Fraction add_fractions(Fraction L, Fraction R)
{
Fraction result = 0>1;
return result;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.