google.com, pub-6167773875660516, DIRECT, f08c47fec0942fa0 Write a c program to find roots of a quadratic equation - 2nd puc computer science

Write a c program to find roots of a quadratic equation

write a c program to find the roots of a quadratic equation using if else,write a c program to find the roots of a quadratic equation ax2 bx c 0,write a program to solve quadratic equation in c,quadratic equation program in c,how to find roots of quadratic equation,write a c program to find the roots of a quadratic equation ax2 + bx + c = 0

Write a c program to find roots of a quadratic equation

#include<stdio.h>

#include<conio.h>

#include<math.h>

void main()

{

float x1,x2,imaginarypart,realpart,discriminant,a,b,c;

clrscr();

printf("Enter the values of a, b, c: ");

scanf("%f%f%f",&a,&b,&c);

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

if(discriminant>0)

{

x1=(-b+sqrt(discriminant))/(2*a);

x2=(-b-sqrt(discriminant))/(2*a);

printf("Roots are real and different:\n");

printf("x1=%f and x2=%f",x1,x2);

}

else if(discriminant==0)

{

x1=-b/(2*a);

printf("Roots are real and equal\n");

printf("x1=x2=%f",x1);

}

else

{

realpart=-b/(2*a);

imaginarypart=sqrt(-discriminant)/(2*a);

printf("Roots are imaginary\n");

printf("%f+%fi",realpart,imaginarypart);

printf("%f-%fi",realpart,imaginarypart);

}

getch();

}

Output

 

run 1:

Enter the values of a, b, c: 1

2

3

Roots are imaginary

-1.000000+1.414214i-1.000000-1.414214i

 

run 2:

Enter the values of a, b, c: 1

5

6

Roots are real and different:

x1=-2.000000 and x2=-3.000000

 

run 3:

Enter the values of a, b, c: 1

4

4

Roots are real and equal

x1=x2=-2.000000

Write a c program to find roots of a quadratic equation Write a c program to find roots of a quadratic equation Reviewed by Vision Academy on December 17, 2021 Rating: 5

No comments:

CheckOut

Powered by Blogger.