diff --git a/C/Language/C/basicArithmeticCalculator.c b/C/Language/C/basicArithmeticCalculator.c new file mode 100644 index 0000000..49b63d5 --- /dev/null +++ b/C/Language/C/basicArithmeticCalculator.c @@ -0,0 +1,36 @@ +/* + Author : Meghwant singh + Date : 08/10/2021 + Description : Basic Arithmetic Calculator in C language . + */ + +#include + +int main() { + char op; + double first, second; + printf("Enter an operator (+, -, *, /): "); + scanf("%c", &op); + printf("Enter two operands: "); + scanf("%lf %lf", &first, &second); + + switch (op) { + case '+': + printf("%.1lf",first + second); + break; + case '-': + printf("%.1lf", first - second); + break; + case '*': + printf("%.1lf",first * second); + break; + case '/': + printf("%.1lf",first / second); + break; + // If operator doesn't match any case constant + default: + printf("operator is not correct"); + } + printf("\n"); + return 0; +} diff --git a/C/basicArithmeticCalculator/basicArithmeticCalculator.c b/C/basicArithmeticCalculator/basicArithmeticCalculator.c new file mode 100644 index 0000000..9f2cd09 --- /dev/null +++ b/C/basicArithmeticCalculator/basicArithmeticCalculator.c @@ -0,0 +1,37 @@ + /* + Author : Meghwant singh + Date : 08/oct/2021 + Description : basic arithmetic calculator + - * using C language + */ + // basic arithmetic calculator + - * / % + +#include + +int main() { + char op; + double first, second; + printf("Enter an operator (+, -, *, /): "); + scanf("%c", &op); + printf("Enter two operands: "); + scanf("%lf %lf", &first, &second); + + switch (op) { + case '+': + printf("%.1lf",first + second); + break; + case '-': + printf("%.1lf", first - second); + break; + case '*': + printf("%.1lf",first * second); + break; + case '/': + printf("%.1lf",first / second); + break; + // If operator doesn't match any case constant + default: + printf("operator is not correct"); + } + printf("\n"); + return 0; +}