Get three input at the same time: scanf : Switch « Language Basics « C / ANSI-C






Get three input at the same time: scanf


#include <stdio.h>

int main(void)
{
  int i, j;
  char op;

  printf("Enter operation(+ - * /): ");
  scanf("%d%c%d", &i, &op, &j);

  switch(op) {
    case '+': printf("%d", i + j);
      break;
    case '-': printf("%d", i - j);
      break;
    case '/': if(j) printf("%d", i / j);
      break;
    case '*': printf("%d", i * j);
  }

  return 0;
}


           
       








Related examples in the same category

1.a simple 4 function calculator
2.Switch demo
3.How to use switch: number
4.How to use switch: char
5.Switch: char and nested if
6.Switch inside for loop
7.Switch with int case
8.Switch with char case
9.Console menu: switch with char case
10.Switch with default