Results 1 to 2 of 2

Thread: Convert C function to Vb .net [Resolved]

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2004
    Posts
    13

    Convert C function to Vb .net [Resolved]

    I tried to covert this but couldnt figure out what i missed
    (I think % is mod????? as i dont know C )

    Code:
    int
    sum(int n)
    {
    	int	ret;
    
    	ret = 0;
    
    	while (n > 0) {
    		ret = ret + (n % 10);
    		n = n / 10;
    	}
    
    	return (ret);
    }
    VB Code:
    1. Public Function sum(ByVal n As Integer) As Integer
    2.  
    3.         Dim ret As Integer = 0
    4.  
    5.         Do While n > 0
    6.             ret = ret + (n Mod 10)
    7.             n = n / 10
    8.         Loop
    9.  
    10.         Return ret
    11.     End Function

    i tested both these functions some times they give the same return value and sometimes they do not...

    If n is 25 they both return 7

    if n is 36 C++ returns 9, vb returns 10


    //////////////////////

    thanx worked great, took me a while to figure out it i got it working properly
    Last edited by James_Carlson; Feb 1st, 2004 at 09:56 PM.

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