2. C PROGRAMMING LAB | Check Now

C PROGRAMMING LAB – 02] Develop a Program to solve simple computational problems using arithmetic expressions and use of each operator leading to the simulation of a Commercial calculator


ALgorithm

  • Step-1: Start
  • Step-2: Read the variables a and b
  • Step-3: Options Desplay
  • Step-4: Read the input choice
  • Step-5: If Choice is
    • 1 then execute step 6
    • 2 then execute step 7
    • 3 then execute step 8
    • 4 then execute step 9
    • Other than above mentioned choice than execute step 10
  • Step-6: Addition of a and b
  • Step-7: Substraction of a and b
  • Step-8: Multiplication of a and b
  • Step-9: Division of a and b
  • Step-10: Invalid choice
  • Step-11: Print the result
  • Step-12: Stop

Flow Chart

C PROGRAMMING - simple calculator flow chart

Program-2 Source Code

#include<stdio.h>
void main()
{
    int a,b;
    int op;

    printf(" 1.Addition\n 2.Subtraction\n 3.Multiplication\n 4.Division\n 5.Remainder\n");
    printf("Enter the values of a & b: ");
    scanf("%d %d",&a,&b);  
    printf("Enter your Choice : ");
    scanf("%d",&op);
    
    switch(op)
    {
        case 1  :
        printf("Sum of %d and %d is : %d",a,b,a+b);
        break;
        case 2  :
        printf("Difference of %d and %d is : %d",a,b,a-b);
        break;
        case 3  :
        printf("Multiplication of %d and %d is : %d",a,b,a*b);
        break;
        case 4  :
        printf("Division of Two Numbers is %d : ",a/b);
        break;
        case 5:
        printf("Remainder of %d and %d is : %d",a,b,a%b);
        break;
        default :
        printf(" Enter Your Correct Choice.");
        break;
    }
}

C PROGRAMMING -Output

Enter the values of a & b:

5

5

Enter your choice

1

Sum of a and b is : 10

C PROGRAMMING -Viva Questions

1] What is a switch statement?

2] What is a case in switch statement?

3] Does default necessary in switch case?

4] How many cases can you have in a switch statement?

Leave a Reply

Your email address will not be published. Required fields are marked *

WhatsApp Icon Join For Job Alerts