
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Find Solution of Linear Equation in C
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
Advertisements