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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:44:50+00:00 2026-05-27T17:44:50+00:00

people! I’ve been told to create next code as homework. If you compile it

  • 0

people!

I’ve been told to create next code as homework.
If you compile it – you’l easely see it’s purpose. Now, my question is whether there is a way to make it shorter (I’m new to C). I must use structs and struct pointers. This might seem a lame question – sorry for that.
As well, I would like to know whether it’s alright to call “main()” repeatedly.

#include <stdio.h>

typedef struct frac{
    int num;
    int den;
};

int reducer( struct frac *fi ){
    if( fi->num == 0 ) return 0;
    if( fi->den == 1 ) return 1;
    if( fi->num % fi->den == 0 ){
        fi->num /= fi->den;
        fi->den /= fi->den;
        return reducer( fi );
    }
    if( fi->num % 2 == 0 && fi->den % 2 == 0 ){
        fi->num /= 2;
        fi->den /= 2;
        return reducer( fi );
    }
    else if( fi->num % 3 == 0 && fi->den % 3 == 0 ){
        fi->num /= 3;
        fi->den /= 3;
        return reducer( fi );
    }
}

int main(){
    char c , tt;
    struct frac one , two , multi , quot , sum , diff , *o , *t , *m , *q , *s , *d;
    printf( "Please, enter the first fraction, ieg. 3/8:\n" );
    scanf( "%d/%d%c" , &one.num , &one.den , &tt );
    printf( "Now the second fraction (numerator/denominator):\n" );
    scanf( "%d/%d%c" , &two.num , &two.den , &tt );
    o = &one;
    t = &two;
    m = &multi;
    q = &quot;
    s = &sum;
    d = &diff;
    m->num = o->num * t->num; // product numerator
    m->den = o->den * t->den; // product denominator
    q->num = o->num * t->den; // quotient numerator
    q->den = o->den * t->num; // quotient denominator and so on...
    s->num = q->num + q->den;
    s->den = m->den;
    d->num = q->num - q->den;
    d->den = m->den;
    reducer( q );
    reducer( m );
    reducer( s );
    reducer( d );
    printf( "%d/%d + %d/%d = %d/%d\n" , o->num , o->den , t->num , t->den , s->num , s->den );
    printf( "%d/%d - %d/%d = %d/%d\n" , o->num , o->den , t->num , t->den , d->num , d->den );
    printf( "%d/%d * %d/%d = %d/%d\n" , o->num , o->den , t->num , t->den , m->num , m->den );
    printf( "%d/%d : %d/%d = %d/%d\n" , o->num , o->den , t->num , t->den , q->num , q->den );
    printf( "\nWould you like to make another calculation? (y/n):\n" );
    scanf( "%c" , &c );
    if( c == 121 || c == 89 ){
        return main();
    }
    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-27T17:44:51+00:00Added an answer on May 27, 2026 at 5:44 pm

    Here are some suggestions:

    • Use a loop instead of recursion. It’s more natural in this scenario, and it doesn’t make the stack grow with each iteration:

      int finish;
      do
      {
          //...
          printf( "\nWould you like to make another calculation? (y/n):\n" );
          scanf( "%c" , &c );
          finish = c != 121 && c == 89;
      }
      while (!finish)
      
    • You can remove all the pointer declarations and work directly with the fractions themselves.

      multi.num = one.num * two.num; // product numerator
      // ...
      reducer(&quot)
      

    Hope it helps!

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

Sidebar

Related Questions

People have been developing own solutions to the following problems: Consistent messaging frameworks for
People use void main() /*empty parens ()*/ I have been taught to write void
hey people hope all is well.. i am trying to create a form in
Content people have been using Word and pasting things into the old unicode system.
People have been embedding and executing VBScript within batch files for a long time.
people! I've gotta send messages with attachments. So i've got some code based on
People at my company see unit testing as a lot of extra work, that
people, i've an issue now.. #include <stdio.h> #include <stdlib.h> typedef struct a { int
Hi people I have the following code (shown below) and I am trying to
Hi people I have been at this for like 5 days and could not

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.