This repository has been archived on 2025-12-15. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
2024-09-20 14:17:13 +03:00

38 lines
853 B
C

// Program to create a simple calculator
#include <stdio.h>
int main() {
char operation;
double n1, n2;
printf("Enter an operator (+, -, *, /): ");
scanf("%c", &operation);
printf("Enter two numbers: ");
scanf("%lf %lf",&n1, &n2);
switch(operation)
{
case '+':
printf("%.1lf + %.1lf = %.1lf \n",n1, n2, n1+n2);
break;
case '-':
printf("%.1lf - %.1lf = %.1lf \n",n1, n2, n1-n2);
break;
case '*':
printf("%.1lf * %.1lf = %.1lf \n",n1, n2, n1*n2);
break;
case '/':
printf("%.1lf / %.1lf = %.1lf \n",n1, n2, n1/n2);
break;
// operator doesn't match any case constant +, -, *, /
default:
printf("Error! operator is not correct\n");
}
return 0;
}