Write a program to find the roots of a quadratic equation using a switch case.
#include <stdio.h>
#include <math.h>
void main (){
float x1,x2,y,z,a,b,c,p;
printf("Enter the Values : \n");
scanf("%f%f%f",&a,&b,&c);
p = (b*b)-4*a*c;
y = sqrt(p);
z = (-c)/b;
x1 = (-b+y)/2*a;
x2 = (-b-y)/2*a;
switch(a==0 && b==0){
case 1 : printf("No Solution\n");
break;
default : switch(a==0){
case 1 : printf("There is only one root %.2f\n",z);
break;
default : switch(p<0){
case 1 :printf("There are no real root !!");
break;
default : printf("There are two real roots : \n%f\n%f",x1,x2);
}
}
}
}
Comments
Post a Comment