For Advertisements on this blog Contact Us at developgram@gmail.com or +91-9923438816

Simple Programming Tutorials For Beginners

Sunday, December 11, 2016

Simple Calculator

/*
Summary: Does addition subtraction multiplication division
*/

# include <stdio.h>
int main()
{
 char operator;
 float num1,num2;

 printf("Enter operator either + or - or * or / : ");
 scanf("%c",&operator);

 printf("Enter two operands: ");
 scanf("%f%f",&num1,&num2);

 switch(operator)
 {
  case '+':
      printf("num1+num2=%.2f",num1+num2);
      break;
  case '-':
      printf("num1-num2=%.2f",num1-num2);
      break;
  case '*':
      printf("num1*num2=%.2f",num1*num2);
      break;
  case '/':
      printf("num2/num1 = %.2f",num1/num2);
      break;
  default:
     /* If operator is other than +, -, * or /, error message is shown */
      printf("Error! operator is not correct");
      break;
 }
 return 0;
}

No comments:

Post a Comment

SEARCH THIS BLOG