# Write a program to find roots of a quadratic equation using functions and switch statements.

## Question

Write a program to find roots of a quadratic equation using functions and switch statements.

## Code

#include<stdio.h> #include<conio.h> #include<math.h> #include<iostream.h> void main() { float a,b,c,x1,x2,disc; clrscr(); printf("Enter the co-efficients\n"); scanf("%f%f%f",&a,&b,&c); disc=b*b-4*a*c; if(disc>0) { x1=(-b+sqrt(disc))/(2*a); x2=(-b-sqrt(disc))/(2*a); printf("The roots are distinct\n"); } if(disc==0) { x1=x2=-b/(2*a); printf("The roots are equal\n"); printf("x1=%f\nx2=%f\n",x1,x2); } else x1=-b/(2*a); x2=sqrt(fabs(disc))/(2*a); printf("The roots are complex\n"); printf("The first root=%f+i%f\n",x1,x2); printf("The second root=%f-i%f\n",x1,x2); getch(); }

## Output

Enter the co-efficients:26

45

56

The roots are complex

The first root=-0.865385+i1.185308

The second root=-0.865385-i1.185308.

## Which Language is Mostly Used in Programming?

See results without voting## Switch..Case

C++ Has a built-in multiple branch selection statement called **switch**. The switch statement successively tests the value of an expression against a list of integer or character constants. When a match is found, the statement associated with that constant are executed.

## Comments 9 comments

thank you very much that was a very detailed and useful information

Hi can you write program for this problem Please?

write a computer program to find the roots of the following equation

f(x) = -1 + 5.5x - 4x2 + 0.5x3

employing the following methods: Graphical, bisection, false position, newton, and secant.

Compute the ture error and compare grphically with the number of iterations for each methods.

Include in your report tilte page and the results

dear i want a project of calendar in c programming....so plz help me .send me as sooon as possible

I want to create a project of official management by c programming, help me.

its wrong.........@ 18 th statement it must be else if...

why we need to print first and second root

i want recursion program as early as possible

thank you

9