C - Programming Language
This course covers the basics of programming in C. Work your way through the videos/articles and I'll teach you everything you need to know to start your programming journey!

Building A Better Calculator

Lesson 19
Author : Afrixi
Last Updated : November, 2017


Table of Content

Code

Copyint num1, num2;
char op;

printf(("Enter num1: ");
scanf("%d", &num1);

printf(("Enter Operator: ");
scanf("%c", &op);

printf(("Enter num2: ");
scanf("%d", &num2);

if(op == '+'){
     printf("%d", num1 + num2);
} else if(op == '-'){
     printf("%d", num1 - num2);
} else if(op == '/'){
     printf("%d", num1 / num2);
} else if(op == '*'){
     printf("%d", num1 * num2);
} else {
     printf("Invalid Operator");
}