Results 1 to 10 of 10

Thread: [2005] Conversion of C code to VB.net

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    449

    Question [2005] Conversion of C code to VB.net

    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;
    }
    Last edited by surya; Jul 9th, 2007 at 09:54 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width