Skip to content

Commit

Permalink
Simple calculator
Browse files Browse the repository at this point in the history
Program to create a simple calculator
  • Loading branch information
suprabhatdas authored Oct 3, 2022
1 parent 135fc41 commit 089ddb2
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions simple_calculator.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <stdio.h>

int main() {

char opr;
double n1, n2;
printf("Enter an operator (+, -, *, /): ");
scanf("%c", &opr);
printf("Enter two operands: ");
scanf("%lf %lf", &n1, &n2);

switch (opr) {
case '+':
printf("%.1lf + %.1lf = %.1lf", n1, n2, n1+n2);
break;
case '-':
printf("%.1lf - %.1lf = %.1lf", n1, n2, n1-n2);
break;
case '*':
printf("%.1lf * %.1lf = %.1lf", n1, n2, n1*n2);
break;
case '/':
printf("%.1lf / %.1lf = %.1lf", n1, n2, n1/n2);
break;
default:
printf("Incorrect Operator!");
}
return 0;
}

0 comments on commit 089ddb2

Please sign in to comment.