Please login

Prime

Prepinsta Prime

Video courses for company/skill based Preparation

(Check all courses)
Get Prime Video
Prime

Prepinsta Prime

Purchase mock tests for company/skill building

(Check all mocks)
Get Prime mock

Accenture Coding Question 8

Coding Question 8

You are required to implement the following function, Int OperationChoices(int c, int n, int a , int b )

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.

Example:

  • Input
    • c :1
    • a:12
    • b:16
  • Output:
    • Since ‘c’=1 , (12+16) is performed which is equal to 28 , hence 28 is returned.

Sample Input

 c : 2

 a : 16

 b : 20

Sample Output

-4

#include<stdio.h>

int operationChoices(int c, int a , int b)

{

    if(c==1)

    {

        return a + b;

    }

    else if(c==2)

    {

        return a - b; 

    }

    else if(c==3)

    {

        return a * b;

    }

    else if(c==4)

    {

        return a / b;

    }

}

int main()

{

    int x, y, z;

    int result;

    scanf("%d",&x);

    scanf("%d",&y);

    scanf("%d",&z);

    result = operationChoices(x, y, z);

    printf("%d",result);

}
Output:
2
16
20
-4
def operationChoices(c,a,b):

    if c == 1 :

        return(a+b)

    elif c == 2:

        return(a-b)

    elif c == 3:

        return(a*b)

    else:

        return(a//b)

c,a,b = map(int,input().split())
print(operationChoices(c, a, b))
Output:
2 16 12 20
-4