#include<iostream> using namespace std; struct phanso { int tu; int mau; }p1,p2; void main() { cout<<"**chuong trinh tinh tong 2 phan so**"<<endl; cout<<"nhap phan so thu nhat: "<<endl; cout<<"tu: ";cin>>p1.tu; do {cout<<"mau: ";cin>>p1.mau;} while(p1.mau==0); cout<<"nhap phan so thu hai: "<<endl; cout<<"tu: ";cin>>p2.tu; do {cout<<"mau: ";cin>>p2.mau;} while(p2.mau==0); int i,a,b; a=p1.tu*p2.mau+p2.tu*p1.mau; b=p1.mau*p2.mau; if(a%b!=0) { if(a>b) for(i=1;i<b;i++) if((a%i==0)&&(b%i==0)) { a=a/i; b=b/i; } else for(i=1;i<a;i++) if((a%i==0)&&(b%i==0)) { a=a/i; b=b/i; } cout<<"tong cua 2 pso: "<<a<<"/"<<b<<endl; } else cout<<"tong cua 2 pso: "<<a/b<<endl; }