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 malloc calloc and realloc in c?

0 Answers  


Can we declare a function inside a function in c?

0 Answers  


Write a program which take a integer from user and tell whether the given variable is squar of some number or not. eg: is this number is 1,4,9,16... or not

9 Answers   Alcatel,


Is c is a procedural language?

0 Answers  


What is a nested formula?

0 Answers  






why we are using semicolon at the end of printh statment

2 Answers   HCL,


Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the maximum number of concurrent threads that the InnoDB plug-in can create.

0 Answers   IBM,


write a program to find the number of even integers and odd integers in a given array in c language

13 Answers   IAI Cameroun, NIIT, Olive Tech, QIS,


What is a c token and types of c tokens?

0 Answers  


Is python a c language?

0 Answers  


Write a C/C++ program that connects to a MySQL server and displays the global TIMEZONE.

0 Answers  


write a program to find lcm and hcf of two numbers??

1 Answers  


Categories