Skip to main content

Quadratic Equation77

Quadratic Equation
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
void main()
{
 float a,b,c,x1,x2,rp,ip,disc;
 printf("enter the co-efficients\n");
 scanf("%f%f%f",&a,&b,&c);
 if((a*b*c)==0)
 {
 printf("a cannot be zero");
 exit(0);
 }
 disc=b*b-4*a*c;
 if(disc==0)
{
 printf("the roots are equal\n");
x1=x2=-b/(2*a);
 printf("x1=%f\n x2=%f\n",x1,x2);
}
 else if(disc>0)
{
 x1=(-b+sqrt(disc))/(2*a);
 x2=(-b-sqrt(disc))/(2*a);
 printf("the roots are real and distinct\n");
 printf("x1=%f\n x2=%f\n",x1,x2);
}
else 
{
 rp=-b/(2*a);
 ip=sqrt(fabs(disc))/(2*a);
 printf("the roots are Complex\n");
 printf("first root=%f+i%f\n",rp,ip);
 printf("second root=%f-i%f\n",rp,ip);
}
}
Quadratic Equation
Start 

Read the co-efficient as a, b, c

if a is equal to 0 display error

else compute disc=(b*b)-(4*a*c) and r=sqrt(fabs(disc)))

if disc is equal to 0 then

compute x1=x2= -b/(a*2.0)) and display x1,x2

else If discriminant is greater than 0 then

compute (x1=(-b+r)/(a*2.0)), x2= (-b-r)/(a*2.0)) and display x1,x2

else If discriminant is lesser than zero,

display roots are complex

compute x1=(-b)/(a*2.0)+ir/(a*2.0) and x2= (-b)/(a*2.0)-ir/(a*2.0) and display x1,x2

Stop

Comments

Popular posts from this blog

Raju is a Civil Engineer. He is writing software to automate his work. As a part of his requirement, he wants to calculate the circle diameter, circumference, and area. Help Raju to complete his task. Get radius as input.

OUTPUT

Implement structures to read, write and compute average- marks and the students scoring above and below the average marks for a class of N students Program and Algorithm Computer Science Engineering VTU

Structures abov below avg #include<stdio.h> struct student { char name [100]; char usn [20]; float marks; }; void main() { int i,j,k,m,n,aboveavg[100],belowavg[100]; float total=0.0,avg=0.0; struct student s[100]; printf("enter number of students\n"); scanf("%d",&n); for(i=0;i<n;i++) { printf("enter the details of students%d\n",i+1); printf("enter name\n"); scanf("%s",s[i].name); printf("enter usn\n"); scanf("%s",s[i].usn); printf("enter marks\n"); scanf("%f",&s[i].marks); total+=s[i].marks; } printf("enter the details of students\n"); printf("name\t\t usn\t\t marks\n"); for(i=0;i<n;i++) printf("%s\t\t %s\t\t %f\n",s[i].name,s[i].usn,s[i].marks); avg=total/n; printf("avg=%f\n",avg); j=0; k=0; for(i=0;i<n;i++) { if(s[i].marks>avg) abov...