Lời giải của tớ nè
Code
#include<iostream.h>
#include<conio.h>
main()
{
cout<<"\n Chuong trinh rut gon phan thuc\n\n\n";
int a[2];
cout<<"Nhap tu so: "; cin>>a[0];
cout<<"Nhap mau so: "; cin>>a[1];
int tick=1;
cout<<"\nPhan so sau khi rut gon: \n\n";
if (a[0]>a[1])
{
for (int i=1;i<=a[1];i++)
if ((a[0]%i==0) && (a[1]%i==0))
{
tick=tick*i;
}
cout<<a[0]/tick<<"/"<<a[1]/tick;
}
else if (a[1]>a[0])
{
for (int j=1;j<=a[0];j++)
if ((a[0]%j==0) && (a[1]%j==0))
{
tick=tick*j;
}
cout<<a[0]/tick<<"/"<<a[1]/tick<<endl;
}
getch();
}