Advertisement
Guest User

LAborki2

a guest
Oct 22nd, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.15 KB | None | 0 0
  1. clc
  2. clear
  3. disp('kalkulator +, -, *, /, ^');
  4. x=input('podaj znak działania: ','s');
  5. if x~= '+ - * / ^';
  6.     disp('podaj dzialanie jeszcze raz');
  7.     x=input('podaj znak działania: ','s');
  8. end
  9. switch x
  10.     case '+'
  11.         a=input('podaj wartosc liczby a= ')
  12.         b=input('podaj wartosc liczby b= ')
  13.         c=a+b;
  14.         disp(['suma=',num2str(round(c,2))])
  15.     case '-'
  16.         a=input('podaj wartosc liczby a= ')
  17.         b=input('podaj wartosc liczby b= ')
  18.         c=a-b;
  19.         disp(['roznica=',num2str(round(c,2))])
  20.     case '*'
  21.         a=input('podaj wartosc liczby a= ')
  22.         b=input('podaj wartosc liczby b= ')
  23.         c=a*b;
  24.         disp(['iloczyn=',num2str(round(c,2))])
  25.     case '/'
  26.         a=input('podaj wartosc liczby a= ')
  27.         b=input('podaj wartosc liczby b= ')
  28.         if b==0
  29.             disp('nie dzielimy przez 0')
  30.         else
  31.             c=a/b;
  32.             disp(['iloraz=',num2str(round(c,2))])
  33.         end
  34.     case '^'
  35.         a=input('podaj wartosc liczby a= ')
  36.         b=input('podaj wartosc liczby b= ')
  37.         c=a^b;
  38.         disp(['potega=',num2str(round(c,2))])
  39.     otherwise
  40.         disp('błąd')
  41. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement