//C program to factorize an algebraic expression with coefficient of leading term 1 and degree 2
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main()
{
int i,c[3],m[2],d=0,x,y,z;
printf("Compare your equation with ax^2+bx+c and input the values for a, b and c\n");
printf("input a"); scanf("%d",&c[1]);
printf("input b"); scanf("%d",&c[2]);
printf("input c"); scanf("%d",&c[3]);
printf("The factors of (%d)x^2+(%d)x+(%d) are",c[1],c[2],c[3]);
d=c[2]*c[2]-4*c[1]*c[3];
x=pow(d,0.5);
y=2*c[1];
z= -1*c[2];
m[1]=(z+x)/y;
m[2]=(z-x)/y;
for (i=1;i<=2;i++)
{printf("(x");
if(m[i]<0)
{printf("+%d)",abs(m[i]));
}
else
{ if (m[i]==0 )
{ printf(")");
}
else
{printf("-%d)",m[i]);
}
}
}
getch();
return 0;
}
No comments:
Post a Comment