473,395 Members | 1,558 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,395 software developers and data experts.

Quadratic equation

hi
i m a student nd need to write a program to input coefficients of a quadratic equation and output its roots .
There is some problem in this , i tried several variations but it is not working.
Please check and let me know what's wrong and how to fix it...
#include <stdio.h>
#include <conio.h>
#include <math.h>

main()
{
float a,b,c,d,r1,r2;

printf("Enter the coefficients ...");
scanf("%f %f %f",&a,&b,&c);

d=((b*b)-(4*a*c));

if (!d<0)
{
if (d=0)
{
r1=((-b)/(2*a));
r2=r1;
}
else
// if (d>0)
{
r1=((-b+sqrt(d))/(2*a));
r2=((-b-sqrt(d))/(2*a));
}

}

printf("%f %f",r1,r2);

getch();
return 0;

}
Apr 13 '08 #1
3 1350
Savage
1,764 Expert 1GB
This:

Expand|Select|Wrap|Line Numbers
  1. if (d=0)
is your problem.You are using assigment operator instead of eqaulity operator which is ==

Also don't use main(),use int main becasue that's what standard says you should use.
Apr 13 '08 #2
JosAH
11,448 Expert 8TB
... and this:

Expand|Select|Wrap|Line Numbers
  1. if (!d<0)
  2.  
evaluates as if you had written this:

Expand|Select|Wrap|Line Numbers
  1. if((!d) < 0)
  2.  
both (see the previous reply) are nonos.

kind regards,

Jos
Apr 13 '08 #3
thnx so much,it works now !
Apr 13 '08 #4

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
2
by: ioannoual | last post by:
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!! ...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.