fork download
  1. ///Or Tsarfati
  2.  
  3. #include <stdio.h>
  4. #define SIZE 122
  5. void main()
  6.  
  7. {
  8. int i=0,j,a=0,b=0;
  9. char targil[SIZE];
  10.  
  11. printf("please insert the Targil\n");
  12. scanf("%s",targil);
  13. while (targil[i]!='=')//the loop turns the chars into ints.
  14. {
  15. if(targil[i]!='+' && targil[i]!='-' && targil[i]!='*' && targil[i]!='/')
  16. targil[i]=targil[i]-'0';
  17. i++;
  18. }
  19. i=0;
  20. do///adding all the numbers to NUM a
  21. {
  22. if(targil[0]=='-' && i!=0)
  23. {
  24. a=a*10;
  25. a=a-targil[i];
  26. }
  27. if(targil[0]!='-')
  28. {
  29. a=a*10;
  30. a=a+targil[i];
  31. }
  32. i++;
  33. }
  34.  
  35. while (targil[i]!='+' && targil[i]!='-' && targil[i]!='*' && targil[i]!='/');
  36.  
  37.  
  38. i++;
  39. j=i;
  40. do///adding all the numbers to NUM b
  41. {
  42. if(targil[i]=='-' && i!=j)
  43. {
  44. b=b*10;
  45. b=b-targil[j];
  46. }
  47. else
  48. if(targil[i]!='-')
  49. {
  50. b=b*10;
  51. b=b+targil[j];
  52. }
  53. j++;
  54. }
  55. while (targil[j]!='=');
  56. i=1;
  57. while(targil[i]!='+' && targil[i]!='-' && targil[i]!='*' && targil[i]!='/')
  58. {
  59. i++;
  60. }
  61. ////below is calculation of numbers
  62. if(targil[i]=='+')
  63. printf("%d+%d=%d\n",a,b,a+b);
  64. else
  65. if(targil[i]=='-')
  66. printf("%d-%d=%d\n",a,b,a-b);
  67. else
  68. if(targil[i]=='*')
  69. printf("%d*%d=%d\n",a,b,a*b);
  70. else
  71. if(targil[i]=='/' && b!=0)
  72. printf("%d/%d=%d\n",a,b,a/b);
  73. else
  74. printf("can't divide by 0\n");
  75.  
  76.  
  77.  
  78. }
Runtime error #stdin #stdout 0s 2172KB
stdin
-52/6=

stdout
please insert the Targil
-52/6=-8