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


Please Help Members By Posting Answers For Below Questions

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

2309


how to test pierrot divisor

2242


How can you relate the function with the structure? Explain with an appropriate example.

2901


could you please send the program code for multiplying sparse matrix in c????

3057


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 ??

1760






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.

2661


What is the difference between proc means and proc tabulate ? explain with a simple example when you have to use means or tabulate?

3692


Write a program to model an exploding firecracker in the xy plane using a particle system

3674


Develop a routine to reflect an object about an arbitrarily selected plane

2972


write a program for area of circumference of shapes

2020


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.

2126


#include int main(void) { int a=4, b=2; a=b<>2 ; printf("%d",a); return 0; }

1052


why nlogn is the lower limit of any sort algorithm?

2358


Design an implement of the inputs functions for event mode

2946


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

6293