0% found this document useful (0 votes)
4 views2 pages

36 Program

The document presents a C program that calculates the roots of a quadratic equation using a switch-case structure. It prompts the user for coefficients a, b, and c, computes the discriminant, and determines the nature of the roots based on its value. The program handles real and complex roots and outputs the results accordingly.

Uploaded by

darkside9547
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

36 Program

The document presents a C program that calculates the roots of a quadratic equation using a switch-case structure. It prompts the user for coefficients a, b, and c, computes the discriminant, and determines the nature of the roots based on its value. The program handles real and complex roots and outputs the results accordingly.

Uploaded by

darkside9547
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

36.

Write a program in ‘c’ to calculate quadratic equation using switch


case.

Ans- #include <stdio.h>


#include<math.h>

void main()

float a,b,c,d,r1,r2;

printf("Enter a,b,c value according a*x*x+b*x+c=0 equation:\n");

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

d=(pow(b,2)-(4*a*c));

switch(d>0)

case 1:

r1=(-b+sqrt(d))/(2*a);

r2=(-b-sqrt(d))/(2*a);

printf("Root1=%.2f and Root2=%.2f",r1,r2);

break;

case 0:

switch(d==0)

case 1:

r1=r2=b/(2*a);
printf("Two Roots are %.2f ,%.2f ",r1,r2);

break;

case 0:

float r1_img,r2_img;

r1=r2=-b/(2*a);

r1_img=r2_img=(sqrt(-d))/(2*a);

printf("Root1=%.2f+%.2fi\n",r1,r2_img);

printf("Root1=%.2f-%.2fi\n",r1,r2_img);

break;

Output-
Enter a,b,c value according a*x*x+b*x+c=0 equation:

123

Root1=-1.00+1.41i

Root1=-1.00-1.41i

You might also like