From e8d28f76ad9f06eff9d5e1ba4982e743fa7281a5 Mon Sep 17 00:00:00 2001 From: Amit kumar <70947616+Amitkumar233@users.noreply.github.com> Date: Thu, 1 Oct 2020 07:16:10 +0530 Subject: [PATCH 1/2] Update README.md --- PracticeProblems/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/PracticeProblems/README.md b/PracticeProblems/README.md index 3916d10..054bc70 100644 --- a/PracticeProblems/README.md +++ b/PracticeProblems/README.md @@ -7,6 +7,7 @@ Feel free to submit your solutions and comments! --- 1. Write a program to given two rectangles find print out if they intersect or not. +2. Write a c program for simple calculator using switch Statement. ---- \ No newline at end of file +--- From 7d6d638aece575179aee2cf28f79edee232d75cd Mon Sep 17 00:00:00 2001 From: Amit kumar <70947616+Amitkumar233@users.noreply.github.com> Date: Thu, 1 Oct 2020 07:17:50 +0530 Subject: [PATCH 2/2] Update README.md --- PracticeProblems/README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/PracticeProblems/README.md b/PracticeProblems/README.md index 054bc70..a1402d2 100644 --- a/PracticeProblems/README.md +++ b/PracticeProblems/README.md @@ -11,3 +11,33 @@ Feel free to submit your solutions and comments! --- +Solution-2 +#include +int main() { + char operator; + double first, second; + printf("Enter an operator (+, -, *,): "); + scanf("%c", &operator); + printf("Enter two operands: "); + scanf("%lf %lf", &first, &second); + + switch (operator) { + case '+': + printf("%.1lf + %.1lf = %.1lf", first, second, first + second); + break; + case '-': + printf("%.1lf - %.1lf = %.1lf", first, second, first - second); + break; + case '*': + printf("%.1lf * %.1lf = %.1lf", first, second, first * second); + break; + case '/': + printf("%.1lf / %.1lf = %.1lf", first, second, first / second); + break; + // operator doesn't match any case constant + default: + printf("Error! operator is not correct"); + } + + return 0; +}