Arithmetic calculator using switch statement

#include
#include
void main()
{
    int choice, no1, no2, result;
    clrscr();
    
    printf("\n\n*********************");
    printf("\nArithmetic Calculator");
    printf("\n*********************");
    printf("\n\n1. Addition\n2. Subtraction");
    printf("\n3. Multiplication\n4. Division");
    printf("\n\nEnter your choice: ");
    scanf("%d",&choice);
    
    switch(choice){
        case 1:
            printf("\nEnter the two number:");
            scanf("%d %d", &no1, &no2);
            result = no1 + no2;
            printf("\nThe Addition of %d and %d is %d", no1, no2, result);
            break;
        case 2:
            printf("\nEnter the two number:");
            scanf("%d %d", &no1, &no2);
            result = no1 - no2;
                        printf("\nThe Subtaction of %d and %d is %d", no1, no2, result);
            break;
        case 3:
            printf("\nEnter the two number:");
            scanf("%d %d", &no1, &no2);
            result = no1 * no2;
            printf("\nThe Multiplication of %d and %d is %d", no1, no2, result);
            break;
        case 4:
            printf("\nEnter the numerator and denominator:");
            scanf("%d %d", &no1, &no2);
            if(no2 == 0){
            printf("\nError: cannot divide by zero");
            }
            else{
            result = no1 / no2;
            printf("\nDivision of %d by %d is %d", no1, no2, result);
            }
            break;
    }
    getch();
}

Output:

*********************
Arithmetic Calculator
*********************
1. Addition
2. Subtraction
3. Multiplication
4. Division
Enter your choice: 4
Enter the numerator and denominator:5 0
Error: cannot divide by zero

You may also like...

9 Responses

  1. Anonymous says:

    now where’s your division ? if denominator is not zero..:)

  2. LearnCOnline says:

    Thanks buddy… 🙂

  3. I really like your working.

  4. Anonymous says:

    amazing

  5. Anonymous says:

    its nice nd easy to learn

  6. Anonymous says:

    you r good

  7. Tajudheen NK says:

    you do best

  8. C program says:

    Thanks .. nice program for beginners.

Leave a Reply

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

FREE C Cheatsheet - Speed Up Your C Programming.

FREE C Cheatsheet - Speed Up Your C Programming.

Download a 7-page free cheat sheet for easy and quick access to C Concepts, Snippets, and Syntax.

Thank you! Check you inbox and access your cheat-sheet