A quadratic equation in c

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ioannoual
    New Member
    • Nov 2007
    • 1

    A quadratic equation in c

    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!!

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    int main(void)
    
    {
    
    float a,b,c,d,root1,root2;
    
    printf("Welcome to the Quadratic Equation Solver\n");
    printf("----------------------------------------\n");
    printf("Please enter the 3 coefficients a, b, c : \n");
    printf("Enter coefficient a: \n");
    scanf("%f", &a);
    printf("Enter coefficient b: \n");
    scanf("%f", &b);
    printf("Enter coefficient c: \n");
    scanf("%f", &c);
    printf("Enter coefficient d: \n");
    scanf("%f", &d);
    
    if(a == 0 && b == 0)
    printf("Both a and b cannot be 0 in ax^2 + bx + c = 0 \n");
    
    }else
    
    d=-c/b;
    {
    printf("The solution of the linear equation is : \n");
    
    
    }else{
    
    d=b*b-4*a*c;
    
    if(d>0)
    
    root1=(-b+sqrt(d))/(2*a);
    root2=(-b-sqrt(d))/(2*a);
    {
    printf("The first root = \n");
    printf("The second root = \n");
    
    return 0;
    }
    }
    I need it as soon as possible!!!

    Thankssss very much!
  • chroot
    New Member
    • Nov 2007
    • 13

    #2
    Why do you have the user enter d?
    Apart from that, the program should work

    Comment

    • MarshMallow
      New Member
      • Nov 2007
      • 52

      #3
      Hi Ioannual,your programs doesn't work simply because there is a big syntax errors in it;the curly brace of main is closed just before the first else clause;i strongly reccommend to use a syntax driven editor;or if you are already using an IDE,pleas turn on the "match braces" options,that will save you a lot of time.
      And please next time attach the messages that the compiler print on screen after compiling,that will help us to find the error.

      Comment

      Working...