fork download
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. int a;
  6. float x;
  7. float y;
  8.  
  9. printf("calculator by 4308\n");
  10. printf("choose the operation:\n1 - sum\n2 - minus\n3 - multiply\n4 - division");
  11. scanf("%d", &a);
  12. printf("\nEnter first number: \n");
  13. scanf("%f", &x);
  14. printf("Enter second number: \n");
  15. scanf("%f", &y);
  16. if (a == 1){
  17. printf("Your result is: %.2f", x+y);
  18. }
  19. else if (a == 2){
  20. printf("Your result is: %.2f", x-y);
  21. }
  22. else if (a == 3){
  23. printf("Yor result is: %.2f", x*y);
  24. }
  25. else if (a == 4){
  26. if(y != 0){
  27. printf("Your result is: %.2f", x/y);
  28. }
  29. else{
  30. printf("Error division by zero");
  31. }
  32. }
  33. else{
  34. printf ("You write invalid choose");
  35. }
  36. return 0;
  37. }
Success #stdin #stdout 0s 5312KB
stdin
1
2
3
stdout
calculator by 4308
choose the operation:
1 - sum
2 - minus
3 - multiply
4 - division
Enter first number: 
Enter second number: 
Your result is: 5.00