Develop a program to solve simple computational problems using arithmetic expressions and use of each operator leading to simulation of a commercial calculator.(No built-in math function)

All QuestionsCategory: C LanguageDevelop a program to solve simple computational problems using arithmetic expressions and use of each operator leading to simulation of a commercial calculator.(No built-in math function)
nikhil.d asked 3 years ago
2 Answers
nikhil.d answered 3 years ago

Algorithm

Step 1: [Start]Step 2: [Read two values]Input num1, num2
Step 3: [display the menu-simple calculation]1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Modulus
Step 4: [Enter choice]Read choice
Step 5: [Switch case]Case 1: result num1 + num2
break;
Case 2: result num1 – num2
break;
Case 3: result num1* num2
break;
Case 4: result num1 / num2
break;
Case 5: result num1 % num2
break;
Step 6: [print the result]Output result
Step 7: [Stop]  

#include<stdio.h>
int main()
{
int a,b,choice;
int result;
printf(“Enter two values\n”);
scanf(“%d%d”,&a,&b);
printf(“enter your choice\n”);
printf(“1.Addition\n 2.Subtraction\n 3.Multiplication\n 4.Division\n 5.Modulus\n”);
scanf(“%d”,&choice);
switch(choice)
{
case 1: result = a + b;
break;
case 2: result = a – b;
break;
case 3: result = a * b;
break;
case 4: result = a / b;
break;
case 5: result = a % b;
break;
default:printf(“invalid choice”);
}
printf(“The Result = %d”,result);
return 0;
}

Chetan Shidling Staff answered 3 years ago

Note: Change the double inverted comma ( ” ) in the code to avoid an error.