473,396 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

A quadratic equation in c

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
2 2592
chroot
13
Why do you have the user enter d?
Apart from that, the program should work
Nov 29 '07 #2
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

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

Similar topics

3
by: parisgoblet | last post by:
hi, i'm a freshman with c++,i got a question from my assignment,does someone could give me some ideas for that. Given the following prototype of a function that solves the roots of a quadratic...
1
by: tedla | last post by:
i want a fragment of code that accepts the coefficient of quadratic equation from user and calculate the eqt'n.
6
by: chronoxx251 | last post by:
Hi, I'm doing a school project where I need to make a program to calulate the quadratic equation. Now, I already got that part taken care of with the following code: #include "stdafx.h" #include...
6
by: Trev17 | last post by:
Hello, I am new to C++ and i have tried for several hours to make a program my teacher has given me as a lab. Here is the Lab question: the roots of the quadratic equation ax^2 + bx + c = 0, a...
5
by: mulhadhevi | last post by:
Can anyone tell me how to write a program to find the roots of the quadratic equation using switch case.
2
by: DaRok28 | last post by:
// Program Description: // This program solves quadratic equations to find their roots. This // program takes values of a, b, and c as input and outputs the root(s). // The user can repeat the...
4
by: nbkreddy | last post by:
write a program to find the roots of the quadratic equation using switch statement
1
by: bbench123 | last post by:
Make a program that will ask for values of a quadratic equation (ax2+bx+c). the program must determine the roots of the equation using the quadratic equation determinants to distinguish if the roots...
1
by: candacefaye1 | last post by:
1. write a C++ program to decide if the coefficients of a quadratic equation have real roots. The three choices will be to write the message “zero divide” when A is zero, write the message “no real...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.