Advertisement
rozman50

Untitled

Nov 18th, 2018
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5.  
  6. /* krajšanje */
  7. int g(int &s, int &i, int &v, int &z){
  8. v=s*i;
  9.  
  10. z=s % i ;
  11. while (z>0){
  12. s=i;
  13. i=z;
  14.  
  15. z=s % i ;
  16. }
  17. cout << "Najvecji skupni delitelj je " << i << endl;
  18.  
  19. }
  20.  
  21. /* seštevanje */
  22. void r(int a, int b, int c, int d, int &s, int &i, int &v, int &z){
  23. if (c == d){
  24. s= a+b;
  25. i= c;
  26. cout <<"rezultat je "<< s<<" / "<< i << endl;
  27. g(s,i,v,z);
  28.  
  29.  
  30.  
  31. }
  32. else {
  33. i=c*d;
  34. s= (a*d)+(b*c);
  35. cout<<"rezultat je "<< s <<" / " << i <<endl;
  36. g(s,i,v,z);
  37. }
  38. }
  39.  
  40. /* odštevanje */
  41. void o(int a, int b, int c, int d, int &s, int &i, int &v, int &z){
  42. if (c == d){
  43. s= a-b;
  44. i= c;
  45. cout <<"rezultat je "<< s <<" / "<< i << endl;
  46. g(s,i,v,z);
  47. }
  48. else {
  49. i=c*d;
  50. s= (a*d)-(b*c);
  51. cout<<"rezultat je "<< s <<" / " << i <<endl;
  52. g(s,i,v,z);
  53. }
  54. }
  55.  
  56. /* množenje */
  57. void m(int a, int b, int c, int d, int &s, int &i, int &v, int &z){
  58. s=a*b;
  59. i=c*d;
  60.  
  61. cout <<"rezultat je "<< s <<" / "<< i << endl;
  62. g(s,i,v,z);
  63. }
  64.  
  65. /*deljenje*/
  66. void e(int a, int b, int c, int d, int &s, int &i, int &v, int &z){
  67. s=a*d;
  68. i=c*b;
  69.  
  70. cout <<"rezultat je "<< s <<" / "<< i << endl;
  71. g(s,i,v,z);
  72. }
  73.  
  74.  
  75.  
  76.  
  77.  
  78. /* glauna funkcija */
  79. int main()
  80. {
  81. int a, b, c, d;
  82. int s, i;
  83. int v,z;
  84. char predznak;
  85.  
  86.  
  87. cout << "seštevanje ulomkov" << endl;
  88. cout << "vnesite stevec ";
  89. cin >> a;
  90. cout << "vnesite imenovalec ";
  91. cin >> c;
  92. cout << "vnesite stevec drugega ulomka ";
  93. cin >> b;
  94. cout << "vnesite imenovalec drugega ulomka ";
  95. cin >> d;
  96. cout << "vnesite katero funkcijo bi zeleli racunati (+,-,*,/) ";
  97. cin >> predznak;
  98.  
  99. switch (predznak) {
  100. case '+':
  101. r(a,b,c,d,s,i,v,z);
  102. break;
  103.  
  104. case '-':
  105. o(a,b,c,d,s,i,v,z);
  106. break;
  107.  
  108. case '*':
  109. m(a,b,c,d,s,i,v,z);
  110. break;
  111.  
  112. case '/':
  113. e(a,b,c,d,s,i,v,z);
  114. break;
  115.  
  116. }
  117.  
  118.  
  119.  
  120. return 0;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement