C program | Switch case

Write a c Program on basic math tools using switch case:

Syntax:  

main()
{
    scanf("%d",&choice);
        switch(choice)
        {
        case x:
            ..........
            ..........
        case y:
            ..........
            ..........
        case z:
            ..........
            .......... 
        }
 }

 

code: 

#include<stdio.h>
#include<stdlib.h>
void main()
{
    int choice,a,b,c;
    while(1)
    {
        printf("Basic math Tools:\n");
        printf("1.ADD\n");
        printf("2.SUBTRACT\n");
        printf("3.MULTIPLY\n");
        printf("4.EXIT!\n");
        printf("Choose Any of the following\n");
        scanf("%d",&choice);
        switch(choice)
        {
        case 1:
            printf("Enter two number:\n");
            scanf("%d%d",&a,&b);
            c=a+b;
            printf("The sum is %d \n",c);
            break;
        case 2:
            printf("Enter two number:\n");
            scanf("%d%d",&a,&b);
            c=a-b;
            printf("The sub is %d \n",c);
            break;
        case 3:
            printf("Enter two number:\n");
            scanf("%d%d",&a,&b);
            c=a*b;
            printf("The multiply is %d \n",c);
            break;
        case 4:
            exit(0);    //#include<stdlib.h>
        default:
            printf("Invalid choice");
        }
    }
}

 

Output :


 ----------------------------------------------
Basics in c language : part 1

Comments

Popular posts from this blog

TOP 10 PROGRAMMING LANGAUAGES COMMING 2021 | ARTICLE

Write a C-program to swap two number:

Print Fibonacci Series using Recursion | C program :