From 684b9d5626cca9cf35b8a980ea3ebaaf713bcc64 Mon Sep 17 00:00:00 2001 From: 1abhi23 Date: Thu, 11 Oct 2018 11:15:00 -0700 Subject: [PATCH 1/2] program for calculator --- programs/calculator.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 programs/calculator.c diff --git a/programs/calculator.c b/programs/calculator.c new file mode 100644 index 0000000..38658c1 --- /dev/null +++ b/programs/calculator.c @@ -0,0 +1,38 @@ +#include +#include +int main(){ + //declarations +double num1, num2; +int op; +printf("*********WELCOME*********\n"); +printf("1.Addition\n2.Substration\n3.Multiplication\n4.Division\n"); +printf("enter your choice\n"); +scanf("%d",&op); +printf("Enter first number\n"); +scanf("%lf",&num1); + +printf("Enter second number\n"); +scanf("%lf",&num2); + switch(op){ + case 1: + + printf("=%lf\n", num1+num2); + break; + case 2: + printf("=%lf\n", num1-num2); + break; + case 3: + printf("=%lf\n", num1*num2); + break; + case 4: + if(num2==0){ + printf("Division by zero error!\n"); + }else{ + printf("=%lf\n", num1/num2); + } + break; + + default: printf("Invalid Operator\n"); +} + return 0; +} From 2319e5c3a74d587d4ad072897c61668f947adfb9 Mon Sep 17 00:00:00 2001 From: 1abhi23 Date: Thu, 11 Oct 2018 11:54:39 -0700 Subject: [PATCH 2/2] program of CALCULATOR --- CALCULATOR.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 CALCULATOR.c diff --git a/CALCULATOR.c b/CALCULATOR.c new file mode 100644 index 0000000..b717cce --- /dev/null +++ b/CALCULATOR.c @@ -0,0 +1,34 @@ +#include +#include +int main() +{//declarations +double num1, num2; +int op; +printf("*********WELCOME*********\n"); +printf("1.Addition\n2.Substration\n3.Multiplication\n4.Division\n"); +printf("enter your choice\n"); +scanf("%d",&op); +printf("Enter first number\n"); +scanf("%lf",&num1); +printf("Enter second number\n"); +scanf("%lf",&num2); +switch(op){ + case 1: + printf("=%lf\n", num1+num2); + break; + case 2: + printf("=%lf\n", num1-num2); + break; + case 3: + printf("=%lf\n", num1*num2); + break; + case 4: + if(num2==0) + printf("Division by zero error!\n"); + else + printf("=%lf\n", num1/num2); + break; + default: printf("Invalid Operator\n"); + } +return 0; +}