void reduce(int* m, int* n) { int a,b,c; a=*m; b=*n; // НОД a b - алгоритм Евклида do { c=a%b; a=b; b=c; } while (b>0); *m/=a; *n/=a; }
int main() { int m,n; cout<<"input m n "; cin>>m>>n; cout<<m<<"/"<<n<<" = "; reduce(&m,&n); if (n>1) cout<<m<<"/"<<n<<endl; else cout<<m<<endl; system("pause"); return 0; }
using namespace std;
void reduce(int* m, int* n) {
int a,b,c;
a=*m; b=*n;
// НОД a b - алгоритм Евклида
do {
c=a%b; a=b; b=c; }
while (b>0);
*m/=a; *n/=a;
}
int main() {
int m,n;
cout<<"input m n "; cin>>m>>n;
cout<<m<<"/"<<n<<" = ";
reduce(&m,&n);
if (n>1) cout<<m<<"/"<<n<<endl;
else cout<<m<<endl;
system("pause");
return 0;
}
input m n 25 15
25/15 = 5/3