#include #include using namespace std; int deljivost(int a, int b){ for(int i=2;i<=a;i++){ if(a % i==0 && b % i == 0){ return i; } } return 0; } int main(){ int a, b, c, d, operacija; int negativnost = 0; int x=0, y=0, q=0, z=0; //vpis cout << "a/b operator c/d" << endl; cout << "vpisi a"; cin >> a; cout << "vpisi b"; cin >> b; cout << "vpisi c"; cin >> c; cout << "vpisi d"; cin >> d; cout << "1 = +\n" "2 = -\n" "3 = *\n" "4 = /\n"; cin >> operacija; //izračunaj switch (operacija){ case 1: x = (a*d)+(c*b); y = b*d; break; case 2: x = (a*d)-(c*b); y = b*d; break; case 3: x = a*c; y = b*d; break; case 4: x = a*d; y = b*c; } //negativnost if(x<0 && y<0){ negativnost = 0; x = abs(x); y = abs(y); }else if(x<0 && y>=0){ negativnost = 1; x = abs(x); y = abs(y); }else if(x>=0 && y<0){ negativnost = 1; x = abs(x); y = abs(y); }else{ negativnost = 0; } // okrajsa ulomek z = deljivost(x,y); while(z>0){ x = x/z; y = y/z; z = deljivost(x,y); } //izpostavi q = x/y; x = x-(q*y); //izpisi cout << "Rezultat je: "; if(negativnost == 1){cout << "-";} if(q>0){cout << q << " ";} if(x>0){cout << x << "/" << y;} cout << endl; return 0; }