| | |
quadratic equation
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jun 2004
Posts: 5
Reputation:
Solved Threads: 0
#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
•
•
Join Date: Mar 2004
Posts: 1,620
Reputation:
Solved Threads: 51
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
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
•
•
Join Date: Mar 2004
Posts: 1,620
Reputation:
Solved Threads: 51
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
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
Please dont post such huge pics,my connection is slow at the best and it take a long time to download huge pic :-(
•
•
•
•
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
Dont forget to spread the reputation to those that deserve!
![]() |
Similar Threads
- Simple Quadratic Equation Solver - C++ - Do You Have Any Advices Would Like to Give? (C++)
- solving a quadratic equation (C++)
- representing a quadratic equation (C)
- Help me out in Quadratic equation problem (C)
- Quadratic Equation (C)
Other Threads in the C Forum
- Previous Thread: Debugging Link errors
- Next Thread: help by sorting a simply linked list
| Thread Tools | Search this Thread |
#include * ansi append array arrays asterisks binarysearch calculate changingto char character cm convert copyimagefile cprogramme creafecopyofanytypeoffileinc database dynamic execv feet fflush fgets file fork forloop framework function getlasterror givemetehcodez grade gtkwinlinux hacking hardware histogram inches include incrementoperators input intmain() iso kernel keyboard km license linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix microsoft motherboard mqqueue number oddnumber odf opendocumentformat opensource overwrite owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv recvblocked research reversing scanf scripting segmentationfault sequential socket socketprograming standard string systemcall testing threads turboc unix user variable voidmain() wab whythiscodecausesegmentationfault windowsapi






