program to find the roots of a quadratic equation
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
main() { int i; float *pf; pf = (float *)&i; *pf = 100.00; printf("\n %d", i); } a. Runtime error. b. 100 c. Some Integer not 100 d. None of the above
how can i search an element in an array
2 Answers CTS, Microsoft, ViPrak,
Write a procedure to implement highlight as a blinking operation
what is brs test reply me email me kashifabbas514@gmail.com
#define f(g,g2) g##g2 main() { int var12=100; printf("%d",f(var,12)); }
To reverse an entire text file into another text file.... get d file names in cmd line
#include <stdio.h> main() { char * str = "hello"; char * ptr = str; char least = 127; while (*ptr++) least = (*ptr<least ) ?*ptr :least; printf("%d",least); }
Declare an array of N pointers to functions returning pointers to functions returning pointers to characters?
main(){ char a[100]; a[0]='a';a[1]]='b';a[2]='c';a[4]='d'; abc(a); } abc(char a[]){ a++; printf("%c",*a); a++; printf("%c",*a); }
#define prod(a,b) a*b main() { int x=3,y=4; printf("%d",prod(x+2,y-1)); }
Program to find the largest sum of contiguous integers in the array. O(n)
Write a program to receive an integer and find it's octal equivalent. How can i do with using while loop.