pages

Monday, 31 May 2021

c-program to find the roots of the quadratic equations | c-programming

Program to find the Roots of quadratic equation.

In this program ,we will now takes input as the coefficients of quadratic equations by the user and calculate the roots of the quadratic equations in c-programming.  


#include<stdio.h>
#include<conio.h>
void main()
{
         int a,b,c,D;
         float x,y;
         printf("enter the cofficients of x^x , x and constant:-");
         scanf("%d %d %d",&a,&b,&c);
         D=b*b-(4*a*c);
         if(D<0){
                  printf("\n roots are not possible i,e imaginary roots ");
         }
         if(D==0){
                  printf("\n both roots are equals");
                  x=(-1*b)/(2*a);
                  y=(-1*b)/(2*a);
                  printf("\n the roots are %.2f and %.2f",x,y);
         }
         if(D>0){
                  printf("\n the roots are real and distinct ");
                  x=((-1*b)+sqrt(D))/(2*a);
                  y=((-1*b)-sqrt(D))/(2*a);
                  printf("\n the Roots are %.2f and %.2f",x,y);
         }
         getch();
}

output:-




For more c-programming:-


No comments:

Post a Comment