Header Ads Widget

A C program for switch and arthmetic opreation

 #include<stdio.h>

int main()

{

int num1 , num2, sum ,diff, product, divide;

char arth;


printf("Enter num 1 and num2");

scanf("%d%d",&num1,&num2);


printf("Enter what do you want + - * / ");

scanf("%c", &arth);


switch(arth)

    {

   

    case'+':

   

    sum= num1 + num2;

    printf("The sum is %d", sum);

    break;

   

    case'-':

    diff= num1 - num2;

    printf("The diff is %d", diff);

    break;

   

   

    case'*':

    product= num1 * num2;

    printf("The product is %d", product);

    break;

   

   

    case'/':

       if (num2 == 0)

   {

                printf("Cannot divide by zero\n");

                break;

            }  

    divide= num1 / num2;

    printf("The divide  is %d", divide);

   

    break;

   

    default:

    printf("U did something wrong do again noobbb ;)");

   

}

}


I hope that you found this example code helpful! If you have any questions or if you would like to see more examples of code in action, feel free to search this blog or leave a comment below. I am  always happy to help and provide more resources for those looking to improve their programming skills.

Post a Comment

1 Comments

  1. #include
    void main()
    {
    int sales;

    printf("enter your sales amount");
    scanf("%d", &sales);

    if(sales<5000)
    {
    printf("you got 0 percent comission be a good seller -_-");
    }
    else if (sales>=5000 && sales<10000)
    {
    printf("you got 5 percent comiision sell more man :)) ");
    }

    else if (sales>=10000 && sales<15000)
    {
    printf("you got 7 percent comission sell more man :)) ");
    }

    else
    {
    printf("Nice yooou got 10 percent comission good job");
    }
    }

    ReplyDelete