Results 1 to 8 of 8
  1. #1

    Default Help Again! My C Program not giving the desired output


    Mga bro, naa miy assignment sa among IT class. One of the problems was to solve for a quadratic formula. I already have made a C program out of it pero it doesn't seem to give the desired output. T_T

    Mao ni akong program:
    Code:
    #include<stdio.h>
    #include<conio.h>
    #include<math.h>
    int main()
    {
     int a, b, c;
     long double rt1, rt2, div, key;
     clrscr();
     printf("Enter three integers separated by a space: ");
     scanf("%d %d %d", &a, &b, &c);
     div=b*b-(4*a*c);
     if (a==0)
      printf("The given constants does not represent a quadratic equation");
     else if (div>=0)
     {
      key=sqrt(div);
      rt1=((-1*b)+key)/(2*a);
      rt2=((-1*b)-key)/(2*a);
      printf("Quadratic Root one: %f", rt1);
      printf("\nQuadratic Root two: %f", rt2);
     }
     else
      printf("Constants cannot represent the quadratic formula");
     getch();
    }
    Any help is greatly appreciated! Thanks mga bro!
    Last edited by marcdaven; 02-21-2010 at 05:39 PM. Reason: Grammar correction & main() correction

  2. #2
    Elite Member
    Join Date
    Aug 2008
    Posts
    1,053
    Blog Entries
    1
    1. consider using float and not double.
    2. your root1 & root2 have the same formula in any situation? are you sure about this?
    3. how do you handle distinct roots? equal roots? and complex roots?
    4. the way you find discriminant seems okay.
    5. make use of fabs() function in C, you might need it to combined with sqrt() func.

  3. #3
    aguy, quadratic equation.... pass ko ani, pirting bugua bya nako aning math.. nyehehehehe

  4. #4
    Quote Originally Posted by MarkCuering View Post
    1. consider using float and not double.
    2. your root1 & root2 have the same formula in any situation? are you sure about this?
    They are actually different. The formula is this:



    That's why ang root 1 kay add while ang root 2 kay minus...

    Quote Originally Posted by MarkCuering View Post
    3. how do you handle distinct roots? equal roots? and complex roots?
    4. the way you find discriminant seems okay.
    I get what you mean by the discriminant pero wala ko naka G sa imong distinct roots, equal roots and complex roots bro... T_T

    Quote Originally Posted by MarkCuering View Post
    5. make use of fabs() function in C, you might need it to combined with sqrt() func.
    Going to try this...

  5. #5
    Quote Originally Posted by MarkCuering View Post
    5. make use of fabs() function in C, you might need it to combined with sqrt() func.
    So far, I have been comparing given examples sa books nako diri sa amo with the output sa program and it turned out nga ning tugma sila. The fabs() function did help me in this.

    You're the best MarkCuering!

  6. #6
    nag nose bleed ko ani na thread... first nako ni ma bangga na terms...

  7. #7
    nosebleed pud ko ani. :P



    MarkCuering can take care of that marcdaven....

  8. #8
    Elite Member
    Join Date
    Aug 2008
    Posts
    1,053
    Blog Entries
    1
    Quote Originally Posted by marcdaven View Post
    I get what you mean by the discriminant pero wala ko naka G sa imong distinct roots, equal roots andcomplex roots bro T_T
    dba you get the discriminant?

    if discriminant > 0 = is it disctinct roots?
    if discriminant == 0 is it equal roots?


    check this site: Solve Quadratic Equations Using Discriminants (1)

    If D > 0, the equation has 2 real solutions. (see example 1 below)
    If D = 0, the equation has 1 real solution. (see example 2 below)
    If D < 0, the equation has 2 conjugate imaginary solutions. (see example 3 below)



    some pseudocode:

    1. get discriminant b*b-4*a*c
    2. check if disriminant > 0 or equal to 0.
    3. if > 0: our root1 is (-b+sqrt(d))
    and root2 is (-b-sqrt(d))/(2*a)
    4. if discriminant == 0 our root1=root2=-b/(2*a)
    5. figure it out the last one ^_^


    I suggest to change your variable name to these: a,b,c,x1,x2,d

  9.    Advertisement

Similar Threads

 
  1. re: Need help w/ my NERO 7.0 it will not install
    By msinternetcafe in forum Software & Games (Old)
    Replies: 2
    Last Post: 11-28-2007, 08:21 AM
  2. Replies: 18
    Last Post: 10-15-2007, 06:31 PM
  3. Configuring XAMPP to my domain not in the localhost. Is it possible?
    By afortaliza in forum Software & Games (Old)
    Replies: 0
    Last Post: 03-06-2007, 04:39 PM
  4. HELP: My PS1 is not functioning.
    By exorcist in forum Gizmos & Gadgets (Old)
    Replies: 9
    Last Post: 10-11-2006, 08:17 AM
  5. Replies: 2
    Last Post: 09-14-2005, 08:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top