quadratic equation

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2004
Posts: 5
Reputation: hkpkguy is an unknown quantity at this point 
Solved Threads: 0
hkpkguy hkpkguy is offline Offline
Newbie Poster

quadratic equation

 
1
  #1
Jun 5th, 2004


#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
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 1,620
Reputation: kc0arf is a jewel in the rough kc0arf is a jewel in the rough kc0arf is a jewel in the rough 
Solved Threads: 51
Team Colleague
kc0arf kc0arf is offline Offline
Posting Virtuoso

Re: quadratic equation

 
1
  #2
Jun 6th, 2004
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 5
Reputation: hkpkguy is an unknown quantity at this point 
Solved Threads: 0
hkpkguy hkpkguy is offline Offline
Newbie Poster

Re: quadratic equation

 
0
  #3
Jun 6th, 2004
double a = b = c = disc = x1 = x2 = 0.0;

It uses equal? i dun get it?

scanf all variables?
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 1,620
Reputation: kc0arf is a jewel in the rough kc0arf is a jewel in the rough kc0arf is a jewel in the rough 
Solved Threads: 51
Team Colleague
kc0arf kc0arf is offline Offline
Posting Virtuoso

Re: quadratic equation

 
0
  #4
Jun 7th, 2004
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
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 256
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: quadratic equation

 
0
  #5
Jun 7th, 2004
Please dont post such huge pics,my connection is slow at the best and it take a long time to download huge pic :-(
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 10
Reputation: abu_sager is an unknown quantity at this point 
Solved Threads: 2
abu_sager abu_sager is offline Offline
Newbie Poster

Re: quadratic equation

 
0
  #6
Jun 7th, 2004
Hello , this was my homework in the past
i hope it will help you
Attached Files
File Type: cpp polynomial.cpp (3.2 KB, 37 views)
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 5
Reputation: hkpkguy is an unknown quantity at this point 
Solved Threads: 0
hkpkguy hkpkguy is offline Offline
Newbie Poster

Re: quadratic equation

 
0
  #7
Jun 7th, 2004
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 5
Reputation: hkpkguy is an unknown quantity at this point 
Solved Threads: 0
hkpkguy hkpkguy is offline Offline
Newbie Poster

Re: quadratic equation

 
0
  #8
Jun 7th, 2004
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 5
Reputation: hkpkguy is an unknown quantity at this point 
Solved Threads: 0
hkpkguy hkpkguy is offline Offline
Newbie Poster

Re: quadratic equation

 
0
  #9
Jun 7th, 2004
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 759
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Solved Threads: 35
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

Re: quadratic equation

 
1
  #10
Jun 7th, 2004
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.
Dont forget to spread the reputation to those that deserve!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC