943,454 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 7347
  • C RSS
Jun 5th, 2004
1

quadratic equation

Expand Post »


#include <stdio.h>
#include <math.h>
void main()
{
double a,b,c,disc,x1,x2;
printf("To find the roots of a quadriatic equation with real roots\n")
disc=b*b-4*a*c
if(disc<0)
printf("The roots are complex",disc);
if(disc>=0)
printf("-b+sqrt(disc)/2a",x1);
printf("-b-sqrt(disc)/2a",x2);


This is what i wrote, i know it is missing alot
but I really dunno how to do it, so can anyone help me to do the rest
so it can run well
Similar Threads
Reputation Points: 11
Solved Threads: 0
Newbie Poster
hkpkguy is offline Offline
5 posts
since Jun 2004
Jun 6th, 2004
1

Re: quadratic equation

Hello,

To start with, when you declare variables, initialize them right away:

double a = b = c = disc = x1 = x2 = 0.0;

Next, you will need to use cin or scanf to read the data into variables.

You will also need to check your operator precidence. Example:

4 * 3 / 4 + 6 = 9

4 * 3 / (4 + 6) = 4 * 3 / 10 = 1.2

Your disc equation will need help.

Let us know how it works.

Christian
Team Colleague
Reputation Points: 121
Solved Threads: 57
Posting Virtuoso
kc0arf is offline Offline
1,629 posts
since Mar 2004
Jun 6th, 2004
0

Re: quadratic equation

double a = b = c = disc = x1 = x2 = 0.0;

It uses equal? i dun get it?

scanf all variables?
Reputation Points: 11
Solved Threads: 0
Newbie Poster
hkpkguy is offline Offline
5 posts
since Jun 2004
Jun 7th, 2004
0

Re: quadratic equation

Hello,

double a = b = c = disc = x1 = x2 = 0.0;

declares all of those variables as double values, and then assigns them a value of zero.

Remember that in C, = is the assign operator, and == is the equals operator.

scanf(%d, variable); scans in an integer
scanf(%lf, variable); scans in a floating double number

You are going to need to read your C or C++ book to find out how to set these things up properly, and gain a greater understanding of what you are trying to do.

Give it a shot.

Christian
Team Colleague
Reputation Points: 121
Solved Threads: 57
Posting Virtuoso
kc0arf is offline Offline
1,629 posts
since Mar 2004
Jun 7th, 2004
0

Re: quadratic equation

Please dont post such huge pics,my connection is slow at the best and it take a long time to download huge pic :-(
Reputation Points: 108
Solved Threads: 7
Posting Whiz in Training
FireNet is offline Offline
256 posts
since May 2004
Jun 7th, 2004
0

Re: quadratic equation

Hello , this was my homework in the past
i hope it will help you
Attached Files
File Type: cpp polynomial.cpp (3.2 KB, 116 views)
Reputation Points: 12
Solved Threads: 2
Newbie Poster
abu_sager is offline Offline
10 posts
since Jun 2004
Jun 7th, 2004
0

Re: quadratic equation

Quote originally posted by FireNet ...
Please dont post such huge pics,my connection is slow at the best and it take a long time to download huge pic :-(
sorry about that
Reputation Points: 11
Solved Threads: 0
Newbie Poster
hkpkguy is offline Offline
5 posts
since Jun 2004
Jun 7th, 2004
0

Re: quadratic equation

Quote originally posted by abu_sager ...
Hello , this was my homework in the past
i hope it will help you
urs is too hard for me
Reputation Points: 11
Solved Threads: 0
Newbie Poster
hkpkguy is offline Offline
5 posts
since Jun 2004
Jun 7th, 2004
0

Re: quadratic equation

This is my project thats due tomorrow
can someone do the rest for me?
i am lack of time now....
coz i got my final tomorrow too
Reputation Points: 11
Solved Threads: 0
Newbie Poster
hkpkguy is offline Offline
5 posts
since Jun 2004
Jun 7th, 2004
1

Re: quadratic equation

Quote originally posted by hkpkguy ...
This is my project thats due tomorrow
can someone do the rest for me?
i am lack of time now....
coz i got my final tomorrow too
they dont do others homework here, your going to have to do it, best that you can hope for is a direction to go in, and maybe some hints, but you cant expect someone to just write all the code for you.
Reputation Points: 152
Solved Threads: 39
Master Poster
Killer_Typo is offline Offline
778 posts
since Apr 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Debugging Link errors
Next Thread in C Forum Timeline: help by sorting a simply linked list





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC