Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- /* krajšanje */
- int g(int &s, int &i, int &v, int &z){
- v=s*i;
- z=s % i ;
- while (z>0){
- s=i;
- i=z;
- z=s % i ;
- }
- cout << "Najvecji skupni delitelj je " << i << endl;
- }
- /* seštevanje */
- void r(int a, int b, int c, int d, int &s, int &i, int &v, int &z){
- if (c == d){
- s= a+b;
- i= c;
- cout <<"rezultat je "<< s<<" / "<< i << endl;
- g(s,i,v,z);
- }
- else {
- i=c*d;
- s= (a*d)+(b*c);
- cout<<"rezultat je "<< s <<" / " << i <<endl;
- g(s,i,v,z);
- }
- }
- /* odštevanje */
- void o(int a, int b, int c, int d, int &s, int &i, int &v, int &z){
- if (c == d){
- s= a-b;
- i= c;
- cout <<"rezultat je "<< s <<" / "<< i << endl;
- g(s,i,v,z);
- }
- else {
- i=c*d;
- s= (a*d)-(b*c);
- cout<<"rezultat je "<< s <<" / " << i <<endl;
- g(s,i,v,z);
- }
- }
- /* množenje */
- void m(int a, int b, int c, int d, int &s, int &i, int &v, int &z){
- s=a*b;
- i=c*d;
- cout <<"rezultat je "<< s <<" / "<< i << endl;
- g(s,i,v,z);
- }
- /*deljenje*/
- void e(int a, int b, int c, int d, int &s, int &i, int &v, int &z){
- s=a*d;
- i=c*b;
- cout <<"rezultat je "<< s <<" / "<< i << endl;
- g(s,i,v,z);
- }
- /* glauna funkcija */
- int main()
- {
- int a, b, c, d;
- int s, i;
- int v,z;
- char predznak;
- cout << "seštevanje ulomkov" << endl;
- cout << "vnesite stevec ";
- cin >> a;
- cout << "vnesite imenovalec ";
- cin >> c;
- cout << "vnesite stevec drugega ulomka ";
- cin >> b;
- cout << "vnesite imenovalec drugega ulomka ";
- cin >> d;
- cout << "vnesite katero funkcijo bi zeleli racunati (+,-,*,/) ";
- cin >> predznak;
- switch (predznak) {
- case '+':
- r(a,b,c,d,s,i,v,z);
- break;
- case '-':
- o(a,b,c,d,s,i,v,z);
- break;
- case '*':
- m(a,b,c,d,s,i,v,z);
- break;
- case '/':
- e(a,b,c,d,s,i,v,z);
- break;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement