Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include<iostream>
- using namespace std;
- int gcd(int n, int m)
- {
- int gcd, remainder;
- while (n != 0)
- {
- remainder = m % n;
- m = n;
- n = remainder;
- }
- gcd = m;
- return gcd;
- }
- void reduce ( int numerator, int denominator, int * reduce_numerator, int * reduce_denominator)
- {
- int temp = 0;
- temp = gcd(numerator, denominator);
- cout << numerator/temp << endl;
- cout << denominator/temp << endl;
- *reduce_numerator = numerator/ temp;
- *reduce_denominator = denominator/ temp;
- }
- int main(void){
- int numerator, denominator;
- int * reduce_numerator = NULL ;
- int * reduce_denominator = NULL;
- printf("Please enter a fraction: ");
- scanf("%d/%d",&numerator,&denominator);
- //cout << numerator << " & " << denominator << endl;
- reduce(numerator, denominator, reduce_numerator, reduce_denominator);
- printf("In lowest terms: %d/%d", *reduce_numerator,*reduce_denominator);
- printf("the value is: %d",*reduce_numerator/ *reduce_denominator );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement