Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are required to write a C program to carry outa strict-left-to-right evaluat

ID: 3613500 • Letter: Y

Question

You are required to write a C program to carry outa strict-left-to-right evaluation of an arithmeticexpression consisting of integer constants and the operators+, , , and/. Here, the operator / denotes integerdivision; that is, the remainder is discarded. In astrict-left-to-right evaluation, there is no notion of precedence.For example, the value of the expression6+43 when evaluated in a strict-left-to-right fashion is 30.(Under usual precedence rules, where multiplication has higherprecedence than addition, the value of the above expression wouldbe 18.) Similarly, the value of the expression 6 +4 * 3/7 9 when evaluated in a strict-left-to-right fashionis 5.

Explanation / Answer

please rate - thanks #include #include int main() {char input; int i,sum=0,j=0,op=-1; printf("Enter expression: "); scanf("%c",&input); while(input!=' ') {if(input!=' ')     {if(j==0)         {j=1-j;         input-=48;        if(input9)            {printf("Input error - number expected %c found ",input+48);            getch();            return 1;            }          switch(op)            {case -1: sum=(int)input;    //initialcase                       break;             case 0:   sum+=(int)input;    //add                       break;             case 1:   sum-=(int)input;    //sub                       break;             case 2:   if((int)input==0)   //div                           {printf("Division by zero attempted. ");                           getch();                           return 2;                           }                        sum/=(int)input;                        break;             case 3:    sum*=(int)input;   //mult                        break;              }          }      else         {j=1-j;          switch(input)             {case '+': op=0;                         break;              case '-': op=1;                         break;              case '/': op=2;                         break;              case '*': op=3;                         break;               default: printf("Input error - operator expected %cfound ",input);                         getch();                         return 3;             }          }     } scanf("%c",&input); } if(j==0)    printf("Input error - number expected end ofline found "); else    printf("value equals = %d",sum); getch(); return 0; }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote