este funciona en C
Código C:
Ver originalmain()
{
int i;
clrscr();
printf("||\t\tEquation Solver\t\t||\n"); printf("Format of equation : \n"); printf("2. ax+by+c=0\n dx+ey+f=0\n"); printf("4. ax^3+bx^2+cx+d=0\n"); printf("\nEnter number for format : "); if(i==1)
lin1();
if(i==2)
lin2();
if(i==3)
quad();
if(i==4)
cubic();
}
lin1()
{
float a,b,c,x;
clrscr();
printf("Enter a,b and c separated by commas :\n"); scanf("%f,%f,%f",&a
,&b
,&c
); x = (c-b)/a;
rep();
}
lin2()
{
float a,b,c,d,e,f,x,y;
clrscr();
printf("ax + by+ c = 0\ndx + ey + f = 0"); printf("\nEnter a,b,c,d,e and f separated by commas : \n"); scanf("%f,%f,%f,%f,%f,%f",&a
,&b
,&c
,&d
,&e
,&f
); x = ((f*b)-(c*e))/((a*e)-(d*b));
y = ((c*d)-(f*a))/((a*e)-(d*b));
printf("\n x = %f\n y = %f",x
,y
); rep();
}
quad()
{
float a,b,c,x1,x2,d;
clrscr();
printf("\nEnter a,b,c separated by commas : \n"); scanf("%f,%f,%f",&a
,&b
,&c
); if(d>=0)
{
x2
= (-b
-(sqrt(d
)))/(2*a
);printf("\nRoot 1 : %f\nRoot 2 : %f",x1
,x2
); }
if(d<0)
{
d
= ((4*a
*c
)-pow(b
,2))/(2*a
);printf("\nRoot 1 : %f+%fi",((-b
)/(2*a
)),d
); printf("\nRoot 2 : %f-%fi",((-b
)/(2*a
)),d
); }
rep();
}
cubic()
{float a,b,c,d,x1,x2,x3,disc;
int i;
float expr;
clrscr();
printf("ax^3 + bx^2 + cx + d = 0\n Enter a,b,c,d : \n"); scanf("%f,%f,%f,%f",&a
,&b
,&c
,&d
); i = 0;
{
expr
= a
*pow(i
,3)+b
*pow(i
,2)+c
*i
+d
;if(expr==0)
{
x1=i;
break;
}
expr
= a
*pow(-i
,3)+b
*pow(-i
,2)+c
*(-i
)+d
;if(expr==0)
{
x1=-i;
break;
}
i++;
}
b = b + (a*(x1));
c = c + (b*(x1));
disc = (b*b)-(4*a*c);
if(disc>=0)
{
x2
= (-b
+sqrt(disc
))/(2*a
);x3
= (-b
-sqrt(disc
))/(2*a
);printf("\nRoot 2 = %f\nRoot 3 = %f",x2
,x3
); }
else
{
disc
= ((4*a
*c
)-pow(b
,2))/(2*a
);printf("\nRoot 2 : %f+%fi",((-b
)/(2*a
)),disc
); printf("\nRoot 3 : %f-%fi",((-b
)/(2*a
)),disc
); }
rep();
}
rep()
{
char c;
printf("\n\nDo you want to solve for another equation ? y or n\n"); c=getche();
if(c=='y')
main();
}
pero se me hace dificil pasarlo a sintaxis de C#
Igual lo estoy intentado hacer