diff --git a/c_programming/calculator.c b/c_programming/calculator.c index 545061059..0da88e5dd 100644 --- a/c_programming/calculator.c +++ b/c_programming/calculator.c @@ -8,32 +8,33 @@ double num1, num2; char op; printf("Enter the calculation:\n"); -scanf("%lf%c%lf", &num1,&op,&num2); +scanf("%lf %c %lf", &num1,&op,&num2); switch(op){ case '+': - printf("=%lf\n", num1+num2); + printf("%lf + %lf = %lf\n", num1, num2, num1+num2); break; case '-': - printf("=%lf\n", num1-num2); + printf("%lf - %lf = %lf\n", num1, num2, num1-num2); break; case '*': - printf("=%lf\n", num1*num2); + printf("%lf * %lf = %lf\n", num1, num2, num1*num2); break; case '/': if(num2==0){ printf("Division by zero error!\n"); }else{ - printf("=%lf\n", num1/num2); + printf("%lf / %lf = %lf\n", num1, num2, num1/num2); } break; case '%': - printf("=%l\n", (long)num1%(long)num2); + if((long)num2==0){ + printf("Division by zero error!\n"); + }else{ + printf("%lf %% %lf = %ld\n", num1, num2, (long)num1%(long)num2); + } break; default: printf("Invalid Operator\n"); } } - - -