Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cmath>
- using namespace std;
- void summation(double result, double x, double y)
- {
- result = x+y;
- cout << "result of summation is: " << result << endl;
- }
- void subtraction(double result, double x, double y)
- {
- result = x-y;
- cout << "result subtraction is: " << result << endl;
- }
- void multiplication(double result, double x, double y)
- {
- result = x*y;
- cout << "result multiplication je: " << result << endl;
- }
- void division(double result, double x, double y)
- {
- if (y==0)
- {
- cout << "you cannot divide by zero" << endl;
- }
- else
- {
- result = x/y;
- cout << "result division je: " << result << endl;
- }
- }
- void power(double result, double x, double y)
- {
- double p = 1;
- if (y==0)
- {
- result = 1;
- cout << "result of powering: " << result << endl;
- }
- else if (y<0)
- {
- y=abs(y);
- for (unsigned int i=1;i<=y;i++)
- {
- x=1/x;
- result = x;
- }
- cout << "result of powering: " << result << endl;
- }
- else
- {
- for (unsigned int i=1;i<=y;i++)
- {
- p=p*x;
- result = p;
- }
- cout << "result of powering: " << result << endl;
- }
- }
- void faktorial(double result, double x)
- {
- if (x==0)
- {
- x=1;
- }
- else
- {
- for (unsigned int i = x-1; i>0; i--)
- {
- x = x * i;
- }
- }
- cout << "faktorial is: " <<x << endl;
- }
- int main ()
- {
- double x,y,result = 0;
- char a;
- cout << "insert number, operator and number:" << endl;
- cin >> x >> a;
- if (a !='f')
- {
- cin>> y;
- }
- switch (a)
- {
- case '+':
- summation(result, x,y);
- break;
- case '-':
- subtraction(result, x, y);
- break;
- case '*':
- multiplication(result, x, y);
- break;
- case '/':
- division(result, x, y);
- break;
- case 'm':
- power(result, x, y);
- break;
- case 'f':
- faktorial(result,x);
- break;
- default:
- cout << "incorrect input" << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment