To find the roots of a quadratic equation.

Logic : The roots of any quadratic equation of the the form, are,The same equation is computerized here. The program asks user to enter the three coefficients a, b and c. Then it finds out numerator- which is the discriminate, and the denominator of the equation of the roots. Then it checks if the numerator is greater, equals or less than zero. Prints out the results according to the situation.

This can be elaborated to find the roots of equation with higher powers. You are pleased to contact us with your doubts through the discussion forum.







#include
#include
void main()
{
int A, B, C;
float disc, deno, x1, x2;
clrscr();
printf(“\n\n\t ENTER THE VALUES OF A,B,C…”);
scanf(“%d,%d,%d”, &A, &B, &C);
disc = (B * B) – (4 * A * C);
deno = 2 * A;
if(disc > 0)
{
printf(“\n\t THE ROOTS ARE REAL ROOTS”);
x1 = (-B/deno) + (sqrt(disc) / deno);
x2 = (-B/deno) – (sqrt(disc) / deno);
printf(“\n\n\t THE ROOTS ARE…: %f and %f\n”, x1, x2);
}
else if(disc == 0)
{
printf(“\n\t THE ROOTS ARE REPEATED ROOTS”);
x1 = -B/deno;
printf(“\n\n\t THE ROOT IS…: %f\n”, x1);
}
else
printf(“\n\t THE ROOTS ARE IMAGINARY ROOTS\n”);
getch();
}




Related Links :

2 comments:

  1. This is great! Thanks for posting. My mom teaches C++ and I told her to check out your website. She uses different reference materials too. I told her that she can also post her questions in your blog. thanks.

    Tutor

    ReplyDelete


If you face any Problem in viewing code such as Incomplete "For Loops" or "Incorrect greater than or smaller" than equal to signs then please collect from My Web Site CLICK HERE


More Useful Topics...

 

History Of C..

In the beginning was Charles Babbage and his Analytical Engine, a machine
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.

My 1st Program...


#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n");
printf ("\t\t\t*******Pankaj *******\n");
printf ("\t\t\t********************************\n");
printf ("\t\t\t\"Life is Good...\"\n");
printf ("\t\t\t********************************");
getch ();
}

Next Step...


#include
#include

void main ()
{
clrscr ();
printf ("\n\n\n\n\n\n\n\n");
printf ("\t\t\t --------------------------- \n\n");

printf ("\t\t\t | IGCT, Info Computers, INDIA | \n\n");
printf ("\t\t\t --------------------------- ");

getch ();

}

Hits!!!