//WAP TO SOLVE THE QUADRATIC EQUATIONS
#include<conio.h>
#include<stdio.h>
#include<math.h>
void main()
{
float a,b,c,dis,alpha,beta;
char ch;
clrscr();
printf("\nPROGRAM TO CALCULATE THE QUADRATIC EQUATION OF THE FORM:");
printf("\n\n\n\n\t\taX^2+bX+c");
do
{
printf("\n\nENTER THE NUMBER a=");
scanf("%f",&a);
printf("\nENTER THE NUMBER b=");
scanf("%f",&b);
printf("\nENTER THE NUMBER c=");
scanf("%f",&c);
dis=b*b-4*a*c;
printf("\nDISCRIMINANT=%f",dis);
if(dis>0)
{
printf("\n\nTHERE ARE TWO REAL AND DISTINCT ROOTS");
alpha=((-b)+sqrt(dis))/2*a;
beta=((-b)-sqrt(dis))/2*a;
printf("\n\n1.ROOT:ALPHA=%f",alpha);
printf("\n\n2.ROOT:BETA=%f",beta);
}
else
if(dis==0)
{
printf("\n\nROOTS ARE REAL AND EQUAL");
alpha=(-b)/2*a;
beta=(-b)/2*a;
printf("\n\n1.ROOT:ALPHA=%f",alpha);
printf("\n\n2.ROOT:BETA=%f",beta);
}
else
if(dis<0)
printf("\n\nTHERE ARE NO REAL ROOTS");
else
printf("BYE!!BYE!!");
fflush(stdin);
printf("\n\nDO YOU WANT TO CONTINUE?");
scanf("%c",&ch);
}while(ch=='y'||ch=='Y');
getch();
}
/**************************************************************************
OUTPUT
**************************************************************************
PROGRAM TO CALCULATE THE QUADRATIC EQUATION OF THE FORM:
aX^2+bX+c
ENTER THE NUMBER a=1
ENTER THE NUMBER b=3
ENTER THE NUMBER c=2
DISCRIMINANT=1.000000
THERE ARE TWO REAL AND DISTINCT ROOTS
1.ROOT:ALPHA=-1.000000
2.ROOT:BETA=-2.000000
DO YOU WANT TO CONTINUE?y
ENTER THE NUMBER a=1
ENTER THE NUMBER b=4
ENTER THE NUMBER c=6
DISCRIMINANT=-8.000000
THERE ARE NO REAL ROOTS
DO YOU WANT TO CONTINUE?y
ENTER THE NUMBER a=0
ENTER THE NUMBER b=0
ENTER THE NUMBER c=0
DISCRIMINANT=0.000000
ROOTS ARE REAL AND EQUAL
1.ROOT:ALPHA=-0.000000
2.ROOT:BETA=-0.000000
DO YOU WANT TO CONTINUE?n
*/
No comments:
Post a Comment