Friday, 19 February 2016

Find the root of quadratic equation using C



A quadratic equation is a second-order polynomial equation in a single variable x with ax2+bx+c=0, a!=0.

The Quadratic Formula uses the "a", "b", and "c" from "ax2 + bx + c", where "a", "b", and "c" are just numbers; they are the "numerical coefficients" of the quadratic equation they've given you to solve.

The Quadratic Formula is derived from the process of completing the square, and is formally stated as:

For ax2 + bx + c = 0, the value of x is given by:

x  =  [ -b ± sqrt(b2 - 4ac) ] / 2a

Because it is a second-order polynomial equation, the fundamental theorem of algebra guarantees that it has two solutions. These solutions may be both real, or both complex.

For Example Code:

File name : qurdation.c
   

#include<stdio.h> #include<conio.h> #include<math.h> void main() { float a,b,c,d,x1=0,x2=0; clrscr(); 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); d=((b*b)-(4*a*c)); clrscr(); printf("\n| A | %.2f ",a); printf("\n| B | %.2f ",b); printf("\n| C | %.2f ",c); printf("\n-----------------"); printf("\n| D | %.2f",d); if(d==0) { printf("\n\n| Roots are real and equal"); x1=((-b+sqrt(d))/(2*a)); x2=((-b-sqrt(d))/(2*a)); } else if(d>0) { printf("\n\n| Roots are real and distict"); x1=((-b+sqrt(d))/(2*a)); x2=((-b-sqrt(d))/(2*a)); } else if(d<0) { printf("\n\n| Roots are imegnand "); } printf("\n\n| Value of X1 | %.2f",x1); printf("\n| Value of X2 | %.2f",x2); getch(); }

No comments:

Post a Comment

Thanks to comment our blog. i will contact you as soon as possible

Create Thumbnail in Video in Spring and ffmpeg

import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import org.jcodec.api.Fr...