Evaluate simple expressions of the form "number operator number" - C Statement

C examples for Statement:if

Description

Evaluate simple expressions of the form "number operator number"

Demo Code

#include <stdio.h>

int main(void)
{
   float value1, value2;
   char operator1;

   printf("Type in your expression.\n");
   scanf("%f %c %f", &value1, &operator1, &value2);

   if (operator1 == '+')
      printf("%.2f\n", value1 + value2);
   else if (operator1 == '-')
      printf("%.2f\n", value1 - value2);
   else if (operator1 == '*')
      printf("%.2f\n", value1 * value2);
   else if (operator1 == '/')
      printf("%.2f\n", value1 / value2);

   return 0;//from   ww  w.  j  ava2s. co m
}

Result


Related Tutorials