#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
Conclusion: The program is error free
VIVA QUESTIONS:
1) What are various types of loop statements?
Ans : While, do- while, for loop statements
2) 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 b2-4ac
If b2-4ac >0 then roots are real and unequal If b2-4ac =0 then roots are real and equal If b2-4ac <0 then roots are imaginary
4) List out the C features ?
Ans: Portability,flexibility, wide acceptability etc..,
c program on quadratic equation by using switch statement
#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
Conclusion: The program is error free
VIVA QUESTIONS:
1) What are various types of loop statements?
Ans : While, do- while, for loop statements
2) 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 b2-4ac
If b2-4ac >0 then roots are real and unequal If b2-4ac =0 then roots are real and equal If b2-4ac <0 then roots are imaginary
4) List out the C features ?
Ans: Portability,flexibility, wide acceptability etc..,
c program on quadratic equation by using switch statement
No comments:
Post a Comment