Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Given a linear equation in one variable of the form num1 operator num2 = num3 where any one of num1, num2 or num3 is the variable x and other two are integers. Operators can be any one of +, -, / or *, there may or may not be spaces given between the numbers and operator or ‘=’ sign.

Find the value of x.

Note:The equation will always be a valid equation.

Input
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
Each test case contain a single line denoting the linear equation.

Output
For each test case, output a single line containing the value of x correct up to 6 places of decimal.

Constraints
1 = T = 100
the numbers in the equation lie in between -10^9 and 10^9 except 0

Example Input:
3
1+x=12
12/x=2
-8*-x=8

Output:
11.000000
6.000000
1.000000

What I have tried:

I have tried it but I am not able to do it.
Posted
Updated 22-Nov-20 11:04am
v2
Comments
[no name] 22-Nov-20 10:13am    
If you "tried it", then "show it". No dog ate my homework here.

We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
step 1 : pick a language.
step 2 : write logic to open and read a file.
step 3 : write logic to parse the data read from the file
step 4 : write logic to solve the problem from data parsed
step 5 : write logic to output results

Four of those steps involve writing logic and YOU need to do that. It's not our homework.

Here's a tip : since you listed C first, here's documentation for fgets - at C++ Reference[^] and that page includes sample code to open a file, read a line from it with fgets, and close the file. That will be a good start for you.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900