Q. The function accepts 3 positive integers ‘a’ , ‘b’ and ‘c ‘ as its arguments. Implement the function to return.
- ( a+ b ) , if c=1
- ( a - b ) , if c=2
- ( a * b ) , if c=3
- (a / b) , if c =4
Assumption : All operations will result in integer output and the user will enter
appropriate c value.
Java
1 2 3 4 5 6 7 8 9 10 | public static int calculate(int a,int b,int c){ if(c==1) return a+b; else if(c==2) return a-b; else if(c==3) return a*b; else return a/b; } |
Python
def calculate(a,b,c): if c==1: return a+b elif c==2: return a-b elif c==3: return a*b else: return a//b |