write a c program to find the roots of a quadratic equation
ax2 + bx + c = 0

Answers were Sorted based on User's Feedback



write a c program to find the roots of a quadratic equation ax2 + bx + c = 0 ..

Answer / shravya poojitha

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,root;
float x1,x2;
printf("enter the roots a,b,c");
scanf("%d %d %d",&a,&b,&c);
if(a=0&&b=0)
printf("no solution");
else
if(a=0)
{
root=-c/b;
printf("root=%d",root);
}
else
if[(b*b-4*a*c)>0]
{
x1=[-b+sqrt (b*b-4*a*c)]/(2*a);
x2=[-b-sqrt (b*b-4*a*c)]/(2*a);
printf("the roots are x1=%f,x2=%f",x1,x2);
}
else
printf("it has imaginary roots");
getch();
}

Is This Answer Correct ?    142 Yes 49 No

write a c program to find the roots of a quadratic equation ax2 + bx + c = 0 ..

Answer / rohit

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,root;
float x1,x2;
printf("enter the roots a,b,c");
scanf("%d %d %d",&a,&b,&c);
if(a=0&&b=0)
printf("no solution");
else
if(a=0)
{
root=-c/b;
printf("root=%d",root);
}
else
if[(b*b-4*a*c)>0]
{
x1=[-b+sqrt (b*b-4*a*c)]/(2*a);
x2=[-b-sqrt (b*b-4*a*c)]/(2*a);
printf("the roots are x1=%f,x2=%f",x1,x2);
}
else
printf("it has imaginary roots");
getch();
}

Is This Answer Correct ?    29 Yes 21 No

write a c program to find the roots of a quadratic equation ax2 + bx + c = 0 ..

Answer / adhulya

#include<stdio.h>
#include<math.h>
#include<conio.h>
#include<stdlib.h>
void RootsofQuadratic(int a, int b, int c)
{

if (a == 0)
{
printf("The value of a cannot be 0");
return;
}

int d = b*b - 4*a*c;
double SquarerootDescriminant = sqrt(abs(d));

if (d > 0)
{
printf("The Roots are Real in Nature n");
printf("%fn%f",(double)(-b + SquarerootDescriminant)/(2*a)
, (double)(-b - SquarerootDescriminant)/(2*a));
}
else if (d == 0)
{
printf("The roots are equal and Real in Nature n");
printf("%f",-(double)b / (2*a));
}
else // d < 0
{
printf("The Roots are Complex in Nature n");
printf("%f + i%fn%f - i%f", -(double)b / (2*a),SquarerootDescriminant
,-(double)b / (2*a), SquarerootDescriminant);
}
}
int main()
{
int a;
int b;
int c;
printf("For a quadratic equation of form ax2 + bx + c = 0 enter values of a, b, cn");
scanf("%d%d%d", &a, &b, &c);
RootsofQuadratic(a, b, c);
return 0;
}

Is This Answer Correct ?    2 Yes 0 No

write a c program to find the roots of a quadratic equation ax2 + bx + c = 0 ..

Answer / shariful islam

#include<stdio.h>
#include<math.h>

int main(){
float a,b,c;
float d,root1,root2;

printf("Enter quadratic equation in the format ax^2+bx+c: ");
scanf("%fx^2%fx%f",&a,&b,&c);

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

if(d < 0){
printf("Roots are complex number.
");

return 0;
}

root1 = ( -b + sqrt(d)) / (2* a);
root2 = ( -b - sqrt(d)) / (2* a);
printf("Roots of quadratic equation are: %.3f , %.3f",root1,root2);

return 0;
}

Is This Answer Correct ?    0 Yes 0 No

write a c program to find the roots of a quadratic equation ax2 + bx + c = 0 ..

Answer / sagarsp2010

// using sqrt in the program it needs header file <math.h>
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,delta,alpha,beta;
clrscr();

printf("\nENTER THE VALUE OF a:");
scanf("%f",&a);
printf("\nENTER THE VALUE OF b:");
scanf("%f",&b);
printf("\nENTER THE VALUE OF c:");
scanf("%f",&c);

delta=(b*b)-(4*a*c);

if(delta>0)
{
alpha=(-b-sqrt(delta))/(2.0*a);
beta=(-b+sqrt(delta))/(2.0*a);
printf("\nalpha=%f",alpha);
printf("\nbeta=%f",beta);

}
else if(delta==0)
{
printf("\nROOTS ARE REAL");
alpha=-b/(2.0*a);
beta=-b/(2.0*a);
printf("\nalpha=%f",alpha);
printf("\nbeta=%f",beta);
}
else
{
printf("\nROOTS ARE IMAGINARY");
}
getch();
}

Is This Answer Correct ?    23 Yes 25 No

write a c program to find the roots of a quadratic equation ax2 + bx + c = 0 ..

Answer / theara

#include<stdio.h>
#include<conio.h>
void main()
{
float a, b, c;
float x1, x2, root, d;
printf("Enter the values of a, b & c");
scanf("%d %d %d", &a, &b, &c);
if(a==0 && b==0)
printf("There izz no Soln...");
else
if(a=0)
{
root= -c/b;
printf("root = %d", root);
}
else
d = b*b-4*a*c;
if(d>=0)
{
x1 = (-b + d)/2*a;
x2 = (-b - d)/2*a;
printf("Roots are....x1 = %f, x2 = %f\n", x1,x2);
}
else
printf("Given Eqn has imaginary roots");
getch();
}

Is This Answer Correct ?    14 Yes 16 No

write a c program to find the roots of a quadratic equation ax2 + bx + c = 0 ..

Answer / adde.c

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,x1,x2,y,z;
printf("Please Enter 3 inputs of a,b,c in This
format:a<space>b<space>c=");
scanf("%f%f%f",&a,&b,&c);
y=(b*b-4*a*c);
if(a==0&&b==0)
{
printf("There is No Solution!!!!");
}
else if(a==0&&b!=0)
{
x1=(-1)*c/b;
printf("x1=%f",x1);
}
else
{
if(y>=0)
{
z=sqrt(y);
x1=((-1)*b+z)/(2*a);
x2=((-1)*b-z)/(2*a);
printf("Value of x1=%f & x2=%f",x1,x2);
}
else
{
printf("Your Equiation Showing an imaginery
value.....!!!!!!");
}
}
getch();
}

Is This Answer Correct ?    12 Yes 15 No

write a c program to find the roots of a quadratic equation ax2 + bx + c = 0 ..

Answer / abc

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,root;
float x1,x2;
printf("enter the roots a,b,c");
scanf("%d %d %d",&a,&b,&c);
if(a=0&&b=0)
printf("no solution");
else
if(a=0)
{
root=-c/b;
printf("root=%d",root);
}
else
if[(b*b-4*a*c)>0]
{
x1=[-b+sqrt (b*b-4*a*c)]/(2*a);
x2=[-b-sqrt (b*b-4*a*c)]/(2*a);
printf("the roots are x1=%f,x2=%f",x1,x2);
}
else
printf("it has imaginary roots");
getch();
}

Is This Answer Correct ?    8 Yes 11 No

write a c program to find the roots of a quadratic equation ax2 + bx + c = 0 ..

Answer / patel mac p

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int a,b,c,d;
float x1,x2,root;
printf("\nEnter the value of a,b,c");
scanf("%d %d %d",&a,&b,&c);
d=(b*b)-(4*a*c);
if(a==0&&b==0)
{
printf("\nNO SOLUTION");
}
else
if(a==0&&b!=0)
{
root=-c/b;
printf("ROOT=%f",root);
}
else
if(d>=0)
{
printf("\nROOTS ARE REAL");
x1=(-b+sqrt(d))/(2*a);
x2=(-b-sqrt(d))/(2*a);
printf("\nX1=%f",x1);
printf("\nx2=%f",x2);
}
else
if(d<0)
{
printf("\nTHIS EQUATION HAS IMAGINARY ROOTS");
}
getch();
}

Is This Answer Correct ?    11 Yes 15 No

write a c program to find the roots of a quadratic equation ax2 + bx + c = 0 ..

Answer / lazy guyz

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,root;
float x1,x2;
printf("enter the roots a,b,c");
scanf("%d %d %d",&a,&b,&c);
if(a=0&&b=0)
printf("no solution");
else
if(a=0)
{
root=-c/b;
printf("root=%d",root);
}
else
if[(b*b-4*a*c)>0]
{
x1=[-b+sqrt (b*b-4*a*c)]/(2*a);
x2=[-b-sqrt (b*b-4*a*c)]/(2*a);
printf("the roots are x1=%f,x2=%f",x1,x2);
}
else
printf("it has imaginary roots");
getch();
}

Is This Answer Correct ?    1 Yes 7 No

Post New Answer

More C Interview Questions

What is external and internal variables What is dynamic memory allocation what is storage classes in C

3 Answers  


which operator having lowest precedence?? a.)+ b.)++ c.)= d.)%

4 Answers  


What is the difference between getch() and getche()?

1 Answers   NSPL,


What is a node in c?

0 Answers  


Given an array of characters which form a sentence of words, give an efficient algorithm to reverse the order of the words (not characters) in it?

3 Answers  






Predict the output or error(s) for the following: 25. main() { printf("%p",main); }

3 Answers   Google, ME,


Explain the difference between null pointer and void pointer.

0 Answers   TCS,


write a program to copy a string without using a string?

2 Answers  


While compiling a c program,graphics header files are not including in my program..eg: <graphics.h>,what may be the problem...is there any environment settings exists.

2 Answers  


how to write a c program to print list of fruits in alpabetical order?

0 Answers  


why ordinary variable store the later value not the initial

1 Answers  


what about "char *(*(*a[])())();"

3 Answers   Oracle,


Categories