Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

THE ALGORITHM OF QUADRATIC EQUATION

The roots are given by the following formula

1. 2. 3. 4. 5.

Read values of a, b and c, if a is zero then stop as we do not have a quadratic, calculate value of discriminant D=b*b-4*a*c if D is zero then there is one root: x=-b/2*a , if D is > 0 then there are two real roots: -b+sqrt(D)/2*a and bsqrt(D)/2*a. 6. if D is < 0 there will be imaginary roots. 7. Print solution.

C Program to find the roots of quadratic equation


#include<stdio.h> #include<conio.h> void main() { float dis, x1, x2, a, b, c; clrscr(); printf("\n Enter the value of a b c"); scanf("\n%f%f%f",&a,&b,&c); dis=b*b-4*a*c; if (dis>0) { x1=-b/2*a+sqrt(dis)/2*a; x2=-b/2*a-sqrt(dis)/2*a; printf("\none root is=%f",x1); printf("\nsecond root is=%f",x2); }8 else if (dis==0) { x1=-b/2*a; x1=x2; printf("\nRoots are equal%f",x1); } else

{ printf("\n roots are imaginry"); } getch(); }

OUTPUT Enter the value of a b c 1 -5 6 one root is=3.000000 second root is=2.000000

A program to find out the largest number among 10 nos using array.
#include<stdio.h> #include<conio.h> void main() { int a[10],i,big; clrscr(); printf("\n Enter the 10 Nos."); for (i=0; i<10; i++) { scanf("\n%d",&a[i]); } big=a[0]; for (i=1; i<10; i++) { if (big<a[i]) big=a[i]; } printf("\nThe Largest No is %d",big); getch(); }

OUTPUT Enter the 10 Nos. 10 15 9 16 15 8 6 9 7 9 The Largest No is 16

You might also like