Roots of a given quadratic equation in C

c-techaravind


                                              To compile and execute the program, copy the code into a text file. Save the text file with the extinction .c (ex. program.c). Save your file in turboc2 or borland (it may your othe c-compiler). Now open you IDE (tc.exe) , goto file->pick file. Your source file will be loaded into IDE. Now you can compile and run the file easily.







#include<stdio.h>
#include<math.h>
void main()
{
int A, B, C;
float disc, x1, x2;
clrscr();
gotoxy(31,1);
printf("Root of a quadratic equation");
gotoxy(26,3);
printf("http:\\techaravind.blogsopt.com");
gotoxy(1,5);

printf("\n\n\t ENTER THE VALUES OF A,B,C...");
scanf("%d,%d,%d", &A, &B, &C);
disc=(B * B) - (4 * A * C);
if(disc > 0)
{
printf("\n\t THE ROOTS ARE REAL ROOTS");
x1 = (-B/2 * A) + (sqrt((B * B) - (4 * A * C)) /2 * A);
x2 = (-B/2 * A) - (sqrt((B * B) - (4 * A * C)) / 2 * A);
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/2 * A;
printf("\n\n\t THE ROOT IS...: %f\n", x1);
}
else
printf("\n\t THE ROOTS ARE IMAGINARY ROOTS\n");
getch();
}

0 comments:

Post a Comment

 
Etutos © 2010-2011