Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8951343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:38:31+00:00 2026-06-15T13:38:31+00:00

Assuming that these functions are already given: include <stdio.h> /* printf */ include fractions.h

  • 0

Assuming that these functions are already given:

include <stdio.h>     /* printf                         */
include "fractions.h" /* struct FRACTION, add_fractions */

struct FRACTION make_fraction(int numerator, int denominator)
{
  struct FRACTION f;

  f.numerator = numerator;
  f.denominator = denominator;

  return f;
}

void test_fraction(int numerator1, int denominator1, 
                   int numerator2, int denominator2)
{
  struct FRACTION a = make_fraction(numerator1, denominator1);
  struct FRACTION b = make_fraction(numerator2, denominator2);

  struct FRACTION c = add_fractions(&a, &b);

  printf("%i/%i + %i/%i = %i/%i\n", a.numerator, a.denominator,
                                    b.numerator, b.denominator,
                                    c.numerator, c.denominator);
}

void testGCD(void)
{
  int m, n;

  m = 15; n = 18; /* GCD is 3 */
  printf("GCD of %i and %i is %i\n", m, n, GCD(m, n));
  printf("GCD of %i and %i is %i\n", n, m, GCD(n, m));

  m = 80; n = 20; /* GCD is 20 */
  printf("GCD of %i and %i is %i\n", m, n, GCD(m, n));
  printf("GCD of %i and %i is %i\n", n, m, GCD(n, m));

  m = 21; n = 47; /* GCD is 1 */
  printf("GCD of %i and %i is %i\n", m, n, GCD(m, n));
  printf("GCD of %i and %i is %i\n", n, m, GCD(n, m));

  m = 68; n = 153; /* GCD is 17 */
  printf("GCD of %i and %i is %i\n", m, n, GCD(m, n));
  printf("GCD of %i and %i is %i\n", n, m, GCD(n, m));
}

int main(void)
{
  testGCD();

  test_fraction(2, 3, 1, 6);
  test_fraction(1, 5, 4, 9);
  test_fraction(3, 7, 12, 21);
  test_fraction(5, 8, 3, 16);
  test_fraction(7, 8, 3, 12);
  test_fraction(0, 8, 3, 16);
  test_fraction(1, 1, 3, 16);
  test_fraction(5, 8, -3, 16);
  test_fraction(1, 5, -4, 9);
  test_fraction(-1, 5, -4, 9);


  return 0;
}

My task is to write GCD() and add_fractions(), and this is what I have written:

include "fractions.h" 

struct FRACTION add_fractions(const struct FRACTION *a, const struct FRACTION *b)
{                                    
    struct FRACTION c ; /*result struct*/
   /* int GCD_a = GCD(a.numerator, a.denominator);  GCD of the fraction a*/ 
    /*int GCD_b = GCD(b.numerator, b.denominator);  GCD of the fraction b*/

    c.numerator = (a.numerator) + (b.numerator);
    c.denominator = a.denominator ;


    return c;
  /* struct FRACTION empty;*/
   /*return empty;*/
}

int GCD(int a, int b)
{
    /*Variables*/
    int remainder = 0; /*remainder*/
    int larger = a;    
    int smaller = b;

    remainder = larger % smaller;
    while (remainder != 0)
    {
      larger = smaller;
      smaller = remainder;
      remainder = larger % smaller;
    }

    return smaller;
}

Assuming that for the moment both denominators are equals, why I can’t run this with Cygwin? I use this command to compile

gcc -Wall -Wextra -ansi -pedantic -Wno-unused-parameters main.c fractions.c -o fractions.exe    

and I have two errors: (Cygwin is in Spanish on my computer so I am not sure that what I am going to write is the exact translation):

error: trying to put "numerator" in something which is not a struct

(and the same for denominator)

What is the problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:38:32+00:00Added an answer on June 15, 2026 at 1:38 pm
    const struct FRACTION *a, const struct FRACTION *b
    

    So a and b are pointers to a constant struct FRACTION. Then later you write:

    c.numerator = (a.numerator) + (b.numerator);
    

    you don’t access members of struct pointers using ., but using ->, this should be

    c.numerator = a->numerator + b->numerator;
    

    P. s. 1: the parentheses are not needed, don’t put them in superfluously, they decrease readability.

    P. s. 2: your addition formula is broken, use

    c.numerator = a->numerator * b->denominator + b->numerator * a->denominator;
    c.denominator = a->denominator * b->denominator;
    

    instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assuming that the mysqli object is already instantiatied (and connected) with the global variable
I am assuming that the function already has a return value so that cannot
Assuming that I know there is a git-daemon running at git://git.mycompany.com , how can
Is there a cleaner way to do the following, assuming that I have a
Assuming that I have this: enum { A = 0x2E, B = 0x23, C
Assuming that parsing the equation would not be a problem, how can I make
Assuming that the larger a database gets, the longer it will take to SELECT
assuming that I know the PID of a process and want to do a
Assuming that I have a CronTriggerBean similar to <bean id=midMonthCronTrigger class=org.springframework.scheduling.quartz.CronTriggerBean> <property name=jobDetail ref=reminderJobDetail
Assuming that best practices have been followed when designing a new database, how does

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.