By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,549 Members | 1,717 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,549 IT Pros & Developers. It's quick & easy.

A quadratic equation in c

P: 1
Hi...I 'am new in C and I want a program that solves a quadratic equation!!

I try something by my self to write some code about that but I want you to help me writing a new one that will work!!

Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <math.h>
  5.  
  6. int main(void)
  7.  
  8. {
  9.  
  10. float a,b,c,d,root1,root2;
  11.  
  12. printf("Welcome to the Quadratic Equation Solver\n");
  13. printf("----------------------------------------\n");
  14. printf("Please enter the 3 coefficients a, b, c : \n");
  15. printf("Enter coefficient a: \n");
  16. scanf("%f", &a);
  17. printf("Enter coefficient b: \n");
  18. scanf("%f", &b);
  19. printf("Enter coefficient c: \n");
  20. scanf("%f", &c);
  21. printf("Enter coefficient d: \n");
  22. scanf("%f", &d);
  23.  
  24. if(a == 0 && b == 0)
  25. printf("Both a and b cannot be 0 in ax^2 + bx + c = 0 \n");
  26.  
  27. }else
  28.  
  29. d=-c/b;
  30. {
  31. printf("The solution of the linear equation is : \n");
  32.  
  33.  
  34. }else{
  35.  
  36. d=b*b-4*a*c;
  37.  
  38. if(d>0)
  39.  
  40. root1=(-b+sqrt(d))/(2*a);
  41. root2=(-b-sqrt(d))/(2*a);
  42. {
  43. printf("The first root = \n");
  44. printf("The second root = \n");
  45.  
  46. return 0;
  47. }
  48. }
  49.  
  50.  
I need it as soon as possible!!!

Thankssss very much!
Nov 29 '07 #1
Share this Question
Share on Google+
2 Replies


P: 13
Why do you have the user enter d?
Apart from that, the program should work
Nov 29 '07 #2

P: 52
Hi Ioannual,your programs doesn't work simply because there is a big syntax errors in it;the curly brace of main is closed just before the first else clause;i strongly reccommend to use a syntax driven editor;or if you are already using an IDE,pleas turn on the "match braces" options,that will save you a lot of time.
And please next time attach the messages that the compiler print on screen after compiling,that will help us to find the error.
Nov 29 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.