Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include <stdio.h>
  2. #include<iostream>
  3. using namespace std;
  4.  
  5. int gcd(int n, int m)
  6. {
  7. int gcd, remainder;
  8. while (n != 0)
  9. {
  10. remainder = m % n;
  11. m = n;
  12. n = remainder;
  13. }
  14. gcd = m;
  15. return gcd;
  16. }
  17.  
  18.  
  19. void reduce ( int numerator, int denominator, int * reduce_numerator, int * reduce_denominator)
  20. {
  21. int temp = 0;
  22. temp = gcd(numerator, denominator);
  23. cout << numerator/temp << endl;
  24. cout << denominator/temp << endl;
  25. *reduce_numerator = numerator/ temp;
  26. *reduce_denominator = denominator/ temp;
  27.  
  28. }
  29.  
  30. int main(void){
  31. int numerator, denominator;
  32. int * reduce_numerator = NULL ;
  33. int * reduce_denominator = NULL;
  34.  
  35. printf("Please enter a fraction: ");
  36. scanf("%d/%d",&numerator,&denominator);
  37. //cout << numerator << " & " << denominator << endl;
  38. reduce(numerator, denominator, reduce_numerator, reduce_denominator);
  39. printf("In lowest terms: %d/%d", *reduce_numerator,*reduce_denominator);
  40. printf("the value is: %d",*reduce_numerator/ *reduce_denominator );
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement