source file name: roots.c
Program: If coefficients of quadratic equation are input through keyboard. Write a program in C to find the roots of quadratic equation ax2+bx+c=0 whose coefficients are a, b and c.
#include<math.h>
void main()
{
int a,b,c;
float R1,R2;
//clrscr();
printf("\n enter coefficients a, b and c of equation: ");
scanf("%d%d%d",&a,&b,&c);
R1=(-b+sqrt(b*b-4*a*c))/(2*a);
R2=(-b-sqrt(b*b-4*a*c))/(2*a);
printf("\n Root 1: %f and Root 2 : %f ",R1,R2);
getch();
}
output:
0 Comments
Post a Comment