answersLogoWhite

0


Best Answer

#include "stdio.h"

int gcd(int a, int b);

void reduce(int* numerator, int* denominator);

int main(int argc, char* argv[]) {

int a, b;

fscanf(stdin, "%d/%d", &a, &b);

reduce(&a, &b);

fprintf(stdout, "%d/%d", a, b);

return 0;

}

int gcd(int a, int b) {

int c;

while (b) {

c = a % b;

a = b;

b = c;

}

return a;

}

void reduce(int* numerator, int* denominator) {

int g = gcd(*numerator, *denominator);

*numerator /= g;

*denominator /= g;

}

You get the greatest common divisor between the numerator and denominator and divide them by it.

Reduce uses integer pointers so that changes the numerator and denominator to their reduce form.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

There are probably better or easier ways, but the following works.

#include <iostream>

using namespace std;

void Simplify( int * Num, int * Den )

{

int H = 0;

bool b = true;

while( b )

{

b = !b;

for( H = 10; H > 1; --H )

{

if( b = ((*Num) %H 0 ))

{

*Num /= H;

*Den /= H;

break;

}

}

}

}

int main()

{

int N = 0;

int D = 0;

printf( "Input the numerator: " );

scanf( "%u", &N );

printf( "Input the denominator: " );

scanf( "%u", &D );

int n = N;

int d = D;

Simplify( &n, &d );

printf( "%u/%u simplifies to %u/%u\n", N, D, n, d );

return( 0 );

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you get C programming to reduce a fraction?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Create a spiral in C programming?

create spiral in c programming?


What is a C compiler as used in C programming?

In C programming, C compiler is user to translate C source into C object module.


Name of object oriented programming language?

C++ is the name of a programming language.


What is the use of the C language?

The C language (or more commonly C++) is the core of most programming done at the desktop level. Most programs written in Linux are in C or C++, as are most Windows programs. A number of languages in recent computer history have been designed to reduce the dependency on C and C++, but have still largely failed to replace C and C++ for high performance applications.


Why dafault constructor is necessary in c programming?

It is not necessary (nor possible) in C programming.

Related questions

What is c and c in computer programming?

C and C++ are both high-level programming languages.


Create a spiral in C programming?

create spiral in c programming?


What has the author Robert Lafore written?

Robert Lafore has written: 'Object-oriented programming in Microsoft C++' -- subject(s): Object-oriented programming (Computer science), C++ (Computer program language), C. 'Microsoft C. Programming for the I.B.M.Personal Computer' 'Object-oriented programming in C++' 'Windows Programming Made Ridiculously Easy Book' 'The Waite Group's C Programming Using Turbo C++ (The Waite Group)' 'Microsoft C programming for the IBM' 'The Waite Group's Microsoft C programming for the PC' -- subject(s): C (Computer program language), IBM microcomputers, Microsoft C (Computer program), Microsoft C., Programming


When was C - programming language - created?

C - programming language - was created in 1972.


What is a C compiler as used in C programming?

In C programming, C compiler is user to translate C source into C object module.


What is the benefit of the C programming languages?

C language is better for hardware programming .Most of the programming for hardware are written in C language so it is beneficial for hardware programming is not efficient for application programming due to drawback like in C data moves around the system.


Name of object oriented programming language?

C++ is the name of a programming language.


Where can one find C programming tutorials?

You can find C programming tutorials online at the C programming website. They provide both free and paid tutorials for many aspects of the C and C++ code.


What is the use of the C language?

The C language (or more commonly C++) is the core of most programming done at the desktop level. Most programs written in Linux are in C or C++, as are most Windows programs. A number of languages in recent computer history have been designed to reduce the dependency on C and C++, but have still largely failed to replace C and C++ for high performance applications.


Websites to download c C programming language books?

Download 1000s of C C C++ Programming Language. http://www.guruengineers.com


What programming language is Android written in?

Android is programmed in the C and C++ programming language.


Why dafault constructor is necessary in c programming?

It is not necessary (nor possible) in C programming.