I found the following code posted by Louisda16th at http://www.dreamincode.net/code/snippet533.htm
I am wondering if anyone can help me convert the following code to VB.NET..
I will be thankful for any response..
Code:/*Created by Louisda16th/Ashwith*/ #include<stdio.h> #include<math.h> struct complx solvequad( long double p, long double q, long double r, long double s, long double t); struct complx { long double real; long double img; int iscomplex; //0=False, 1 = True }; void main() { int y; long double a,b,c,d,x1,x2; struct complx x3; printf("\n a?");/*Find Coefficients of the equation*/ scanf("%lf",&a); printf("\n b?"); scanf("%lf",&b); printf("\n c?"); scanf("%lf",&c); printf("\n d?"); scanf("%lf",&d); if (d != 0) { x1=0; /*The for loop finds an approximate solution for the equation by using Newton-Raphson Method: x1=x0-(f(x0)/f'(x0)) x2=x1-(f(x1)/f'(x1)) ... ... the solution is more accurate with more iterations*/ for(y=0;y<=100;y++) { x2=x1-(((a*x1*x1*x1)+(b*x1*x1)+(c*x1)+d)/((3*a*x1*x1)+(2*b*x1)+c)); x1=x2; } printf("\n x1=%lf",x2); } else printf("\n x1=0"); /*After one root has been found, we're left with a quadratic equation which can easily be solved using the formula*/ x3 = solvequad(a,b,c,d,x2); if (x3.iscomplex == 0) printf("\n x2=%lf\n x3=%lf\n", x3.real +x3.img, x3.real - x3.img); else printf("\n x2=%lf+i%lf\n x3=%lf-i%lf\n",x3.real, x3.img,x3.real,x3.img); } struct complx solvequad( long double p, long double q, long double r, long double s, long double t) { long double a,b,c,i; struct complx x; a=p; b=q+(t*p); c=(-s)/t; x.real =((-b)/(2*a)); i=((b*b)-(4*a*c)); if (i>=0) { x.img =(sqrt(i))/(2*a); x.iscomplex = 0; } else { x.img =(sqrt(-i))/(2*a); x.iscomplex = 1; } return x; }




Reply With Quote