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

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.

0 Answers   Mbarara University of Science and Technology,


What is "far" and "near" pointers in "c"...?

3 Answers  


Which version do you prefer of the following two, 1) printf(“%s”,str); // or the more curt one 2) printf(str);

1 Answers  


main() { char *cptr,c; void *vptr,v; c=10; v=0; cptr=&c; vptr=&v; printf("%c%v",c,v); }

1 Answers  


To Write a C program to remove the repeated characters in the entered expression or in entered characters(i.e) removing duplicates. String contains only lowercase characters ['a'-'z']

0 Answers  






Display the time of the system and display the right time of the other country

1 Answers  


main() { char *a = "Hello "; char *b = "World"; clrscr(); printf("%s", strcat(a,b)); } a. Hello b. Hello World c. HelloWorld d. None of the above

3 Answers   HCL,


4. Main() { Int i=3,j=2,c=0,m; m=i&&j||c&I; printf(“%d%d%d%d”,I,j,c,m); }

2 Answers   Broadridge,


Write a function to find the depth of a binary tree.

13 Answers   Adobe, Amazon, EFI, Imagination Technologies,


int swap(int *a,int *b) { *a=*a+*b;*b=*a-*b;*a=*a-*b; } main() { int x=10,y=20; swap(&x,&y); printf("x= %d y = %d\n",x,y); }

1 Answers  


write a c program to Create employee record by taking details like name, employee id, address and phone number. While taking the phone number, take either landline or mobile number. Ensure that the phone numbers of the employee are unique. Also display all the details

2 Answers   TCS,


main() { signed int bit=512, i=5; for(;i;i--) { printf("%d\n", bit = (bit >> (i - (i -1)))); } } a. 512, 256, 128, 64, 32 b. 256, 128, 64, 32, 16 c. 128, 64, 32, 16, 8 d. 64, 32, 16, 8, 4

2 Answers   HCL,


Categories