C Program to Solve any Linear Equation in One Variable

This is a C Program to solve linear equation in one variable.

Here is source code of the C Program to Solve any Linear Equation in One Variable. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

  1. #include <stdio.h>
  2. #include <string.h>
  3. float solve_for_y(float a, float b, float c) {
  4. 	float Y = Y = -(b + c) / a;
  5. 	return Y;
  6. }
  7. int main(int argc, char **argv) {
  8. 	float a, b, c, Y;
  9. 	printf(
  10. 			"\nEnter a linear equation in one variable of the form aY + b + c = 0 ");
  11. 	printf("\nEnter the value of a, b, c respectively: ");
  12. 	scanf("%f%f%f", &a, &b, &c);
  13. 	Y = solve_for_y(a, b, c);
  14. 	printf("\nSolution is Y = %f", Y);
  15. 	return 0;
  16. }

Output:

$ gcc SolveLinearEquation.c
$ ./a.out
 
Enter a linear equation in one variable of the form aY + b + c = 0 
Enter the value of a, b, c respectively: 2 4 8
Solution is Y = -6.000000

Sanfoundry Global Education & Learning Series – 1000 C Programs.

advertisement
advertisement

Here’s the list of Best Books in C Programming, Data Structures and Algorithms.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.