__Description:__
Nature of roots of quadratic
equation can be known from the quadrant ê = b

^{2}-4ac
If
b

^{2}-4ac >0 then roots are real and unequal
If
b

^{2}-4ac =0 then roots are real and equal
If
b

^{2}-4ac <0 then roots are imaginary

__Algorithm:__
Step 1: start

Step 2: read the a,b,c value

Step 3: if (b*b-4ac)>0 then

Root 1= (-b+ pow((b*b-4*a*c),0.5))/2*a

Root 2= (-b-pow((b*b-4*a*c),0.5))/2*a

Step 4: if (b*b-4ac)=0 then

Root1
= Root2 = -b/(2*a)

Step 5: Otherwise Print Imaginary
roots. Goto step 7.

Step 6: print roots

Step 7: stop

__Program:__
#include<stdio.h>

#include<math.h>

void main()

{

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

clrscr();

printf("Enter the values for equation:");

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

/* check the condition */

if(a==0)

printf("Enter value should not be zero ");

else

{

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

/* check the condition */

if(d>0)

{

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

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

printf("roots are real and
unequal\n");

printf("%f\n%f\n",r1,r2);

}

else

if(d==0)

{

r1=-b/(2*a);

r2=-b/(2*a);

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

printf("root=%f\n",r1);

printf("root=%f\n",r2);

}

else

printf("roots are imaginary");

}

getch();

}

__Output:__
1. Enter the values for equation: 1, 6, 9

Roots are real and
equal

Root= -3.0000

Root= -3.0000

2. Enter the values for equation: 2, 7, 6

Roots are real
and unequal

Root= -6.75

Root= -7.25

3. Enter the values for equation: 1, 2, 3

Roots are
imaginary

**The program is error free**

__Conclusion:__

__VIVA QUESATIONS:__**What are various types of loop statements?**

__1)__
Ans : While, do-
while, for loop statements

4) What
is the difference between while and do-while statements?

Ans: In while the
condition will be checked first and then enter into a loop.

But in
do- while the statements will be executed first and then finally check the

Condition.

3) How to find the
roots of qudratric equtations ?

Ans: Nature of roots
of quadratic equation can be known from the quadrant

ê
= b

^{2}-4ac
If
b

^{2}-4ac >0 then roots are real and unequal
If
b

^{2}-4ac =0 then roots are real and equal
If b

^{2}-4ac <0 then roots are imaginary
4) List out the C features ?

Ans: Portability,flexibility, wide acceptability etc..,

## No comments:

## Post a Comment