C Program to Build Mini Arithmetic Calculator Using Switch Case on Command Line Full Project For Beginners

  • Post author:
  • Post category:c++
  • Post comments:0 Comments

 

 

main.c

 

 

#include <stdio.h>
int main()
{
int num1, num2, choice, answer;
printf("Enter any two integers : ");
scanf("%d %d ", &num1, &num2);
printf("\nPress 1 for Addition ");
printf("\nPress 2 for Subtraction ");
printf("\nPress 3 for Multiplication ");
printf("\nPress 4 for Division ");
printf("\nPress other key to exit ");
printf("\n\n");
printf("\nEnter ur choice : ");
scanf("%d" ,&choice);
switch(choice)
{
case 1:
answer = num1 + num2;
printf("\n%d + %d = %d ", num1, num2, answer);
break;
case 2:
answer = num1 - num2;
printf("\n%d - %d = %d ", num1, num2, answer);
break;
case 3:
answer = num1 * num2;
printf("\n%d * %d = %d ", num1, num2, answer);
break;
case 4:
answer = num1 / num2;
printf("\n%d / %d = %d ", num1, num2, answer);
break;
default:
printf("\nInvalid Choice ");
}
return 0;
}

Leave a Reply