Friday, March 7, 2014

WRITE A FUNCTION TO CALCULATE AND DISPLAY REAL ROOTS OF A QUADRATIC EQUATION

#include<conio.h>
#include<stdio.h>
#include<math.h>
void main()
{
void root(int,int,int);
int a,b,c,d;
clrscr();
printf("enter the values of constants\n");
scanf("%d%d%d",&a,&b,&c);
d=(b*b-4*a*c);
if(d>0)
{
printf("the real roots of equation are\n");
root(a,b,d);
}
else
printf("roots are imaginary");
getch();
}
void root(int a,int b,int d)
{
int r1,r2;
r1=(-b+sqrt(d))/2*a;
r2=(-b-sqrt(d))/2*a;
printf("r1=%d r2=%d",r1,r2);
}

No comments:

Post a Comment