WRITE A C PROGRAM TO FIND THE ROOTS OF A QUADRATIC EQUATION
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,c,r,i,im;
printf("Enter the value of arbitrary constants of the quadratic equation:\n");
scanf("%d%d%d",&a,&b,&c);
r=-b/2*a;
i=b*b-4*a*c;
if(i<0)
im=-1*i;
else
im=i;
im=(sqrt(im))/2*a;
printf("The 1st root of the equation is: %d+%di",r,im);
printf("The 2nd root of the equation is: %d-%di",r,im);
getch();
}
Output:
Enter the value of the arbitrary constant of the quadratic equation:
1
4
3
The 1st root of the equation is: -2+1i
The 2nd root of the equation is: -2-1i
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,c,r,i,im;
printf("Enter the value of arbitrary constants of the quadratic equation:\n");
scanf("%d%d%d",&a,&b,&c);
r=-b/2*a;
i=b*b-4*a*c;
if(i<0)
im=-1*i;
else
im=i;
im=(sqrt(im))/2*a;
printf("The 1st root of the equation is: %d+%di",r,im);
printf("The 2nd root of the equation is: %d-%di",r,im);
getch();
}
Output:
Enter the value of the arbitrary constant of the quadratic equation:
1
4
3
The 1st root of the equation is: -2+1i
The 2nd root of the equation is: -2-1i
No comments:
Post a Comment