Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

Program to calculate roots of 3 numbers using root1 = (-b + sqrt(discriminant))/(2.0*a) and root2 = (-b - sqrt(discriminant))/(2.0*a) formula

Posted By: Phil Sanchez     Category: C Programming     Views: 3761

Program to calculate roots of 3 numbers using below formula
discriminant = (b*b) - (4*a*c)
root1 = (-b + sqrt(discriminant))/(2.0*a)
root2 = (-b - sqrt(discriminant))/(2.0*a)

Code for Program to calculate roots of 3 numbers using root1 = (-b + sqrt(discriminant))/(2.0*a) and root2 = (-b - sqrt(discriminant))/(2.0*a) formula in C Programming

#include<math.h>

void main()
{
    float a,b,c,discriminant,root1,root2;
    clrscr();

    printf("Input values of a,b and c \n");
    scanf("%f %f %f",&a,&b,&c);

    discriminant = (b*b) - (4*a*c);

    if(discriminant < 0)
    {
        printf("\n\nROOTS ARE IMAGINARY\n");
    }
    else
    {
        root1 = (-b + sqrt(discriminant))/(2.0*a);
        root2 = (-b - sqrt(discriminant))/(2.0*a);
        printf("\n\nRoot1 = %5.2f\n\nRoot2 = %5.2f\n",root1,root2);
    }
    getch();
}
  
Share: 



Phil Sanchez
Phil Sanchez author of Program to calculate roots of 3 numbers using root1 = (-b + sqrt(discriminant))/(2.0*a) and root2 = (-b - sqrt(discriminant))/(2.0*a) formula is from New York, United States.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!