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

Write a program that takes a 5 digit number and calculates 2 power that number and prints it.

1 Answers   Mind Tree,


Can U write a C-program to print the size of a data type without using the sizeof() operator? Explain how it works inside ?

3 Answers   HCL, TCS,


The variables are int sum=10,SuM=20; these are same or different?

3 Answers  


What is the advantage of c?

0 Answers  


largest Of three Number using without if condition?

0 Answers  






I need a help with a program: Write a C program that uses data input in determining the whole of points A and a whole of circles B. Find two points in A so that the line which passes through them, cut through the maximum number of circles.

0 Answers   TCS,


what is the difference between i++ and ++i?

5 Answers  


What are the valid places to have keyword “break”?

0 Answers  


write a program using linked list in which each node consists of following information. Name[30] Branch Rollno Telephone no i) Write the program to add information of students in linked list

0 Answers   Persistent,


1.Why do you call C is middle level language? 2.Why do you call C is userfriendly language.

2 Answers  


Combinations of fibanocci prime series

0 Answers  


How can I open a file so that other programs can update it at the same time?

0 Answers  


Categories