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

Problem 1 Write a C program, calledlinear_solver.c, that solves single-variable

ID: 3616553 • Letter: P

Question

Problem 1

Write a C program, calledlinear_solver.c, that solves single-variable
linear equations. The program should prompt the user to enter alinear
equation of the form

                                    aY + b = c

where a,b, and c are realnumbers of type double. The program should
then output the value of Y that solves the equation, if such avalue
exists(see the note about verifying that a in nonzero). If theinput
provided by the user is not valid, the program should terminatewith
an appropriate error message.

Notes
The character Y should appear in the input as a capital letter.
Introduce this character into the program as a symbolic constantusing
#define, as follows:

#define VARIABLE_NAME ' Y'
When reading the equation using scanf(), you can use the %cconversion
specification to read the character typed-in by the user, thencompare
this character with VARIABLE_NAME.

There should be no spacesin the input between the number a and the
character Y. However, there may or may not be spaces around the +and
= characters.

If there is additionaltext after the equation, but the equation
itself is valid, ignore the additional text and solve the equationas
described above. For an example of this, see the second samplerun.

Verify that the value of ais not zero. If this is not the case,you
should print an appropriate error message and terminate theprogram
using return 1. See the third sample run. Print the value of Ythat
solves the equation with three digits of accuracy after thedecimal
point.

Here are six sample runsof this program, assuming that the executable
file is called linear_solver.

Enter a linear equation:3Y+5=2
Y = -1.000

Enter a linear equation:2Y+ -12 = 0.5 bla blah...
Y= 6.250

Enter a linear equation:0Y+2=1
Invalid equation!

Enter a linear equation:2Y + 5 = 2
Invalid input!

Enter a linear equation:3Y-2=1
Invalid input!

Enter a linear equation:2y+12 = 0.5
Invalid input!

Explanation / Answer

please rate - thanks brute force but it works. some of your examples are incorrect #include #include #define Y 'Y' int main() {int a=0,b=0,c=0,i=0,sign=1,addsub=1; double dec=0,mult=1,sol; char in[30]; printf("Enter a linear equation: "); gets(in); while(in[i]!=Y)     {if(in[i]=='-')        sign=-1;     else        {a=a*mult+(in[i]-48);         mult*=10;         }       i++;      } a*=sign; sign=1; mult=1; i++; while(in[i]!='+'&&in[i]!='-')     {i++;      } if(in[i]=='-')    addsub=-1; i++; while(in[i]==' ')     {i++;     } if(in[i]=='-')      {addsub*=-1;      i++;      } while(in[i]!='='&&in[i]!=' ')     {b=b*mult+(in[i]-48);      mult*=10;       i++;      } i++; while(in[i]==' ')     {i++;     } b*=addsub; if(in[i]=='=')     i++; while(in[i]==' ')     {i++;     } sign=1; mult=1; if(in[i]=='-')     {sign=-1;     i++;     } while(in[i]!='.'&&in[i]!=''&&in[i]!=' ')     {c=c*mult+(in[i]-48);      mult*=10;      i++;      }    if(in[i]=='.')    {i++;     mult=1;     dec=.1;    while(in[i]>=48&&in[i]
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