program to find the roots of a quadratic equation
Answer Posted / asif ahmed
/* PROGRAM TO FIND THE ROOTS OF A QUADRATIC EQUATION WITH
APPROPRIATE ERROR MESSAGE */
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,disc,root1,root2,part_r,part_i;
int flag;
clrscr();
printf("Enter the coefficients of quadratic equation \n");
scanf("%f%f%f",&a,&b,&c);
printf("coefficients are a=%f\t b=%f\t c=%f\n",a,b,c);
if((a==0)||(b==0)||(c==0))
printf("\nZero coefficeints");
else
{
disc=(b*b)-(4*a*c);
if(disc==0)
flag=0;
if(disc>0)
flag=1;
if(disc<0)
flag=2;
switch(flag)
{
case0 : printf("\n Roots are real and equal");
root1=-(-b)/(2*a);
root2=root1;
printf("\n root1=%f",root1);
printf("\n root2=%f",root2);
break;
case1 : printf("\n Roots are real and distinct");
root1=(-b+sqrt(disc))/(2*a);
root2=(-b-sqrt(disc))/(2*a);
printf("\n root1=%f",root1);
printf("\n root2=%f",root2);
break;
case2 : printf("\n Roots are real and Imaginary");
part_r=(-b)/(2*a);
part_i=(sqrt(-disc))/(2.0*a);
printf("\n root1=%f +i%f",part_r,part_i);
printf("\n root2=%f -i%f",part_r,part_i);
break;
}
}
getch();
}
Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
can you use proc sql to manpulate a data set or would u prefer to use proc report ? if so why ? make up an example and explain in detail
how to test pierrot divisor
How can you relate the function with the structure? Explain with an appropriate example.
could you please send the program code for multiplying sparse matrix in c????
Write a Program in 'C' To Insert a Unique Number Only. (Hint: Just Like a Primary Key Numbers In Database.) Please Some One Suggest Me a Better Solution for This question ??
Hi, i have a project that the teacher want a pyramid of numbers in C# or java...when we click a button...the pyramid should be generated in a listbox/or JtextArea...and the pyramid should have the folowing form: 1 232 34543 4567654 567898765 67890109876 7890123210987 890123454321098 90123456765432109 0123456789876543210 Plz help with codes...didn't find anything on the net.
What is the difference between proc means and proc tabulate ? explain with a simple example when you have to use means or tabulate?
Write a program to model an exploding firecracker in the xy plane using a particle system
Develop a routine to reflect an object about an arbitrarily selected plane
write a program for area of circumference of shapes
how to programme using switch statements and fuctions, a programme that will output two even numbers, two odd numbers and two prime numbers of the users chioce.
#include
why nlogn is the lower limit of any sort algorithm?
Design an implement of the inputs functions for event mode
create a C-code that will display the total fare of a passenger of a taxi if the driver press enter,the timer will stop. Every 10 counts is 2 pesos. Initial value is 25.00