C program Simple Calculator Of Addition or Subtraction using Switch Case - HelpMeOutAlways

Friday, June 22, 2018

C program Simple Calculator Of Addition or Subtraction using Switch Case

Source Code


#include<stdio.h>

int
main ()
{
  int menu, add, sub, quit, num1, num2;
  printf ("======================================================\n");
  printf ("Simple Calculator for Addition And Subtraction");
  printf ("======================================================\n");
  printf ("1.Add\n");
  printf ("2.Sub\n");
  printf ("3.Quit\n");
  printf ("Please Select what do you want?\n");
  scanf ("%d", &menu);


  switch (menu)
    {
    case 1:
      printf ("Enter Two Numbers:\n");
      scanf ("%d %d", &num1, &num2);
      add = num1 + num2;
      printf ("Addition =%d", add);
     
      break;
     
    case 2:
      printf ("Enter Two Numbers:\n");
      scanf ("%d %d", &num1, &num2);
      sub = num1 - num2;
      printf ("Subtraction =%d\n", sub);
     
      break;
     
      case 3:
            printf("Program terminated!");
            break;

    default:
      printf ("Wrong Input!");
    }
  return 0;
}

Output:

simple calculator for addition and subtraction

simple calculator program for add and sub

simple calculator for add and sub program c


No comments:

@way2themes