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 6962565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:40:37+00:00 2026-05-27T15:40:37+00:00

This is a program in the book data structures by tanennmbaum, I think the

  • 0

This is a program in the book data structures by tanennmbaum, I think
the code is wrong because outrat->numerator/=a; is not a valid
command, because it has no value assigned to it, please correct me if I
am wrong. Please, correct the code.

#include <iostream.h>
#include <conio.h>
#include <stdio.h>

struct rational
{
  int numerator;
  int denominator;
};

void reduce(struct rational *inrat, struct rational *outrat)
{
  int a, b, rem;

  if (inrat->numerator > inrat->denominator)
  {
    a = inrat->numerator;
    b = inrat->denominator;
  }
  else
  {
    a = inrat->denominator;
    b = inrat->numerator;
  }

  while (b != 0)
  {
    rem = a % b;
    a = b;
    b = rem;
  }

  outrat->numerator /= a;
  outrat->denominator /= a;
}

int equal(struct rational *rat1, struct rational *rat2)
{
  struct rational r1, r2;

  reduce(rat1, &r1);
  reduce(rat2, &r2);

  if (r1.numerator == r2.numerator && r1.denominator == r2.denominator)
    return 1;

  return 0;
}

int main()
{
  struct rational rn1, rn2;
  int k;

  rn1.numerator = 5;
  rn1.denominator = 10;

  rn2.numerator = 1;
  rn2.denominator = 2;

  k = equal(&rn1, &rn2);

  cout << k;
  getch();

  return 0;
}
  • 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-05-27T15:40:38+00:00Added an answer on May 27, 2026 at 3:40 pm

    Replace the lines in question with:

    outrat->numerator = inrat->numerator / a;
    outrat->denominator = inrat->denominator / a;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

/*I got stumped within my code. I think classes will be simpler than structures,
Please check this bellow program. ::Program:: <?php $xml=' &lt;books&gt; &lt;book&gt; &lt;name&gt;Java complete reference&lt;/name&gt; &lt;cost&gt;256&lt;/cost&gt;
Im working on a program that inputs book data in a struct, and deletes
This program I use has it's own variables to set when you run it,
This program stores pairs in a map, counting the number of times a word
This program reads emails (really just a .txt file structured like an email) and
This program I'm doing is about a social network, which means there are users
This program is meant to generate a dynamic array, however it gives an access
For this program #include <iostream> using std::cout; struct C { C() { cout <<
Consider this program int main() { float f = 11.22; double d = 44.55;

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.