program to find the roots of a quadratic equation

Answers were Sorted based on User's Feedback



program to find the roots of a quadratic equation..

Answer / gogol

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,x1,x2,disc,disc1;
clrscr();
printf("Let the quadratic equation is of the form:
a(x^2)+b(x)+c=0; Enter the values of the coefficients:\n");
printf("Enter the value of a: ");
scanf("%f",&a);
printf("Enter the value of b: ");
scanf("%f",&b);
printf("Enter the value of c: ");
scanf("%f",&c);
disc=b*b-4*a*c;
if(disc>0)
{
x1=(-b+sqrt(disc))/(2*a);
x2=(-b-sqrt(disc))/(2*a);
printf("The roots are distinct and they are: %3.3f and
%3.3f",x1,x2);
}
if(disc==0)
{
printf("The roots are equal and it is: %3.3f",-b/(2*a));
}
if(disc<0)
{
disc1=-disc;
x1=-b/(2*a);
x2=sqrt(disc1)/(2*a);
printf("The roots are complex and they are: %3.3f+%3.3fi
and %3.3f-%3.3fi",x1,x2,x1,x2);
}
getch();
}

Is This Answer Correct ?    9 Yes 17 No

program to find the roots of a quadratic equation..

Answer / zainab

#include<conio.h>
#include<stdio.h>
#include<math.h>
void main()
{
int a,b,c;
float d,p,q,r,s;
printf("\n\n Enter the values of a,b,c");
scanf("%d%d%d",&a,&b,&c);
d=(b*b)-(4*a*c);
if(d==0)
{
printf("\n The roots are real and equal");
p=(-b)/(2*a);
q=(-b)/(2*a);
printf("\n The roots of the equation are %f,%f",p,q);
}
if(d>0)
{
printf("\n The roots are real and distinct");
p=((-b)+sqrt((b*b)-(4*a*c)))/(2*a);
q=((-b)-sqrt((b*b)-(4*a*c)))/(2*a);
printf("\n The roots of the equation are %f,%f",p,q);
}
if(d<0)
{
printf("\n The roots are imaginary");
r=(-b)/(2*a);
s=(sqrt((4*a*c)-(b*b)))/(2*a);
printf("\n The roots of the equation are
p=%f+%fi,q=%f-%fi",r,s,r,s);

}
getch();
}

Is This Answer Correct ?    17 Yes 27 No

program to find the roots of a quadratic equation..

Answer / pamali

gogol y did u use 3.3?

Is This Answer Correct ?    5 Yes 16 No

program to find the roots of a quadratic equation..

Answer / shubham singh

//program to find roots of given equation
#include<stdio.h>
#include<math.h>
void main()
{
int a,b,c;
float d,p,q,r,s;
printf("\n\n Enter the values of a,b,c")
scanf("%d%d%d",&a,&b,&c);
d=(b*b)-(4*a*c);
if(d=0)
{
printf("\n The roots are real and equal");
p=(-b)/(2*a);
q=(-b)/(2*a);
printf("\n The roots of the equation are %f,%f",p,q);
}
if(d>0)
{
printf("\n The roots are real and distinct");
p=((-b)+sqrt((b*b)-(4*a*c)))/(2*a);
q=((-b)-sqrt((b*b)-(4*a*c)))/(2*a);
printf("\n The roots of the equation are %f,%f",p,q);
}
if(d<0)
{
printf("\n The roots are imaginary");
r=(-b)/(2*a);
s=(sqrt((4*a*c)-(b*b)))/(2*a);
printf("\n The roots of the equation are
p=%f=%fi,q=%f-%fi",r,s,r,s);
}
}

Is This Answer Correct ?    18 Yes 40 No

Post New Answer

More C Code Interview Questions

main() { clrscr(); } clrscr();

2 Answers  


Cau u say the output....?

1 Answers  


main() { char *p; p="Hello"; printf("%c\n",*&*p); }

1 Answers  


What are the following notations of defining functions known as? i. int abc(int a,float b) { /* some code */ } ii. int abc(a,b) int a; float b; { /* some code*/ }

1 Answers  


main() { unsigned int i=10; while(i-->=0) printf("%u ",i); }

2 Answers   HP,






What is the output for the program given below typedef enum errorType{warning, error, exception,}error; main() { error g1; g1=1; printf("%d",g1); }

1 Answers  


Give a oneline C expression to test whether a number is a power of 2?

25 Answers   EA Electronic Arts, Google, Motorola,


{ int *ptr=(int*)malloc(sizeof(int)); *ptr=4; printf("%d",(*ptr)+++*ptr++); }

4 Answers  


why is printf("%d %d %d",i++,--i,i--);

4 Answers   Apple, Cynity, TCS,


main(){ unsigned int i; for(i=1;i>-2;i--) printf("c aptitude"); }

2 Answers  


print numbers till we want without using loops or condition statements like specifically(for,do while, while swiches, if etc)!

11 Answers   Wipro,


C statement to copy a string without using loop and library function..

2 Answers   Persistent, TCS,


Categories