Skip to content

Instantly share code, notes, and snippets.

@sagarbangade
Created January 11, 2023 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sagarbangade/db2254b8ae5710811215ce94dc154619 to your computer and use it in GitHub Desktop.
Save sagarbangade/db2254b8ae5710811215ce94dc154619 to your computer and use it in GitHub Desktop.
Calculator in C language using Switch case
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("CalculatorS");
int a,b;
printf("Enter first number: ");
scanf("%d",&a);
printf("Enter second number: ");
scanf("%d",&b);
char c;
printf("Enter which type of calculation you want: ");
scanf(" %c",&c);
switch(c)
{
case '+':
printf("addition of %d + %d = %d",a,b,a+b);
break;
case '-':
printf("substraction of %d - %d = %d",a,b,a-b);
break;
case '*':
printf("multiplication of %d * %d = %d",a,b,a*b);
break;
case '/':
printf("division of %d / %d = %d",a,b,a/b);
break;
default:
printf("invalid");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment