- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# C program to find the solution of linear equation

We can apply the software development method to solve the linear equation of one variable in C programming language.

## Requirement

- The equation should be in the form of ax+b=0
- a and b are inputs, we need to find the value of x

## Analysis

Here,

- An
**input**is the**a,b values**. - An
**output**is the x**value**.

## Algorithm

Refer an algorithm given below to find solution of linear equation.

Step 1. Start Step 2. Read a,b values Step 3. Call function Jump to step 5 Step 4. Print result Step 5:

- i. if(a == 0)
- Print value of c cannot be predicted

- Else
- Compute c=-b/a

- Return c

## Program

Following is the C program to find the solution of linear equation −

#include <stdio.h> #include <string.h> float solve(float a, float b){ float c; if(a == 0){ printf("value of c cannot be predicted

"); }else{ c = -b / a; } return c; } int main(){ float a, b, c; printf("

enter a,b values: "); scanf("%f%f", &a, &b); c = solve(a, b); printf("

linear eq of one variable in the form of ax+b = 0, if a=%f,b=%f,then x= %f",a,b,c); return 0; }

## Output

When the above program is executed, it produces the following result −

enter a,b values: 4 8 linear eq of one variable in the form of ax+b = 0, if a=4.000000, b=8.000000, then x= -2.000000

- Related Questions & Answers
- Find Positive Integer Solution for a Given Equation in C++
- C program to find the Roots of Quadratic equation
- Program to find coefficients of linear equations that has only one solution in Python
- C++ Program to Solve any Linear Equation in One Variable
- Find number of solutions of a linear equation of n variables in C++
- C++ Program to Find All Roots of a Quadratic Equation
- Find the Number of Solution to Modular Equations using C++
- Java program to find the roots of a quadratic equation
- Secant method to solve non-linear equation
- Program to find number of solutions in Quadratic Equation in C++
- How to write a C program to find the roots of a quadratic equation?
- Find the number of solutions to the given equation in C++
- Solve a linear matrix equation or system of linear scalar equations in Python
- Which linear function of SciPy is used to solve the circulant matrix equation?
- Program to find out the value of a given equation in Python

Advertisements