#include <stdio.h> #include <stdlib.h> // Function Prototype int getLowestTerms ( int , int , int *, int *); // score simplifies int getGCD ( int , int ); // computing the greatest common divisor void the Output ( int , int , int ); // test int main () { int m, n-, the Num, Denom; int Status; Scanf ( " % D% D " , & m, & n-); Status = getLowestTerms (m, n-, the Num &, & Denom); the Output (Status, the Num, Denom); return 0 ; } // score Simplification // original numerator and denominator by the parameter input // molecule denominator written after simplification variable parameter pointer points int getLowestTerms ( int m, int n-, int * pNum, int * pDenom) { int GCD; int msign = . 1 ; int nsign = . 1 ; int numsign = . 1 ; IF (m == 0 ) { Return 0 ; } the else IF (m == n-) { return . 1 ; } the else IF (n-== 0 ) { return - . 1 ; } the else { // the resulting symbol determination IF (m < 0 ) { msign = - . 1 ; } IF (n-< 0 ) { nsign = - . 1 ; } // results molecules symbol numsign = msign * nsign; m = ABS (m); n- = ABS (n-); * pNum = m; * pDenom = n-; GCD = getGCD (m, n-); * pNum / = GCD; pNum = * * numsign; * pDenom / = GCD; return 2 ; } } // computing the greatest common divisor int getGCD ( int m, int n-) { int REM = n-; the while (REM =! 0 ) { rem = m % n; m = n; n = rem; } return m; } void Output(int status, int nNum, int nDenom) { if(status == 0) { printf("%d\n", status); } else if(status == 1) { printf("%d\n", status); } else if (status == 2) { if(nDenom == 1) // 分母为1 { printf("%d\n", nNum); } else { printf("%d/%d\n", nNum, nDenom); } } else { printf("Error!\n"); } }
Had compiled a flow chart title
Guess you like
Origin www.cnblogs.com/calm-blogme/p/12096750.html
Ranking