fork download
  1. #include <stdio.h>
  2. int main()
  3. {
  4. char opt;
  5. int n1, n2;
  6. int res1;
  7. float res;
  8. printf ("podaj liczbe nr 1:");
  9. if (scanf("%d", &n1) != 1)
  10. {
  11. printf("Incorrect input");
  12. return 1;
  13. }
  14. printf ("podaj liczbe nr 2:");
  15. if (scanf("%d", &n2) != 1)
  16. {
  17. printf("Incorrect input");
  18. return 1;
  19. }
  20. printf ("podaj wazny operator( + , * , - , / ):");
  21. scanf (" %c", &opt);
  22. if (opt == '+')
  23. {
  24. res1 = n1 + n2;
  25. printf ("wynik = %d",res1);
  26. }
  27.  
  28. else if (opt == '-')
  29. {
  30. res1 = n1 - n2;
  31. printf ("wynik = %d",res1);
  32. }
  33.  
  34. else if (opt == '*')
  35. {
  36. res1 = n1 * n2;
  37. printf ("wynik = %d",res1);
  38. }
  39.  
  40. else if (opt == '/')
  41. {
  42. if (n2 == 0)
  43. {
  44. printf("Operation not permitted");
  45. return 2;
  46. }
  47. else
  48. {
  49. res = n1/n2;
  50. printf("wynik = %.2f\n",res);
  51. }
  52. }
  53. return 0;
  54. }
  55.  
Success #stdin #stdout 0s 5404KB
stdin
5
2
*
stdout
podaj liczbe nr 1:podaj liczbe nr 2:podaj wazny operator( + , * , - , / ):wynik = 10