Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Create a Menu-Driven Scientific Calculator

Basic Acceptance 100.00% Points 10.00

You are given a menu choice and the required operand(s). Your task is to perform the selected scientific operation and return the result.

The available operations are:

  • Choice 1: Calculate the square root of a number.
  • Choice 2: Calculate the power of a base raised to an exponent.
  • Choice 3: Calculate the logarithm of a number to base 10.
  • Choice 4: Calculate the sine of an angle given in degrees.

Use a menu-driven structure to select and perform the appropriate operation. The operands are guaranteed to be within the valid domains for the chosen operation.

Examples
Example 1

Input: choice = 1, x = 16
Output: 4
Explanation: The square root of 16 is 4.

Example 2

Input: choice = 2, base = 2, exp = 10
Output: 1024
Explanation: (2^{10} = 1024).

Example 3

Input: choice = 3, x = 1000
Output: 3
Explanation: (\log_{10}(1000) = 3).

Constraints
  • 1 = choice = 4
  • Operands are within valid domains for the chosen operation.
Companies
Amazon Microsoft Apple ZScaler
Topics
Data Structures Basics
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions