Monday, June 18, 2012

To implement simple calculator using Switch statement


/* To implement simple calculator using Switch statement */

#include<stdio.h>

#include<conio.h>

void main()

{

  float a,b;

  char op,c;

  clrscr();

  printf("\nType in your expression\n");

  scanf("%f %c %f",&a,&op,&b);

  switch(op)

  {

    case '+':

      printf("%f\n",a+b);

      break;

   case '-':

      printf("%f\n",a-b);

      break;

   case '*':

      printf("%f\n",a*b);

      break;

   case '/':

      printf("%f\n",a/b);

      break;

   default:

     printf("Unknown operator!!!\n");

     break;

  }

  getch();

}

 

 

OUTPUT

Type in your expression

7+9

16.000000

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.