Very simple recursive algorithm
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Very simple recursive algorithm

  1. #1
    Join Date
    Jan 2013
    Posts
    8

    Question Very simple recursive algorithm

    Write a recursive algorithm that counts the number of times the integer 0 appears in a list of integers. Write a recurrence for the algorithm and solve it.
    Last edited by psk_002; January 18th, 2013 at 11:51 AM.

  2. #2
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,006

    Re: Very simple recursive algorithm

    [ Moved to its own thread - please do not hijack other threads; new problems should be posted in a new thread ]
    Best Regards,

    BioPhysEngr
    http://blog.biophysengr.net
    --
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  3. #3
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,006

    Re: Very simple recursive algorithm

    As I said before, we can help you learn, not do your homework for you. What progress have you made towards solving this and where are you stuck?
    Best Regards,

    BioPhysEngr
    http://blog.biophysengr.net
    --
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  4. #4
    Join Date
    Jan 2013
    Posts
    8

    Re: Very simple recursive algorithm

    ok fine i ll repost in new thread and more over these are not my homework problems. i am new to coding becz my background s biology. i m learng algorithms fr my thesis work. Hope u under stand

  5. #5
    Join Date
    Feb 2002
    Posts
    4,640

    Re: Very simple recursive algorithm

    Quote Originally Posted by psk_002 View Post
    Write a recursive algorithm that counts the number of times the integer 0 appears in a list of integers. Write a recurrence for the algorithm and solve it.
    And, DONE!

    Viggy

  6. #6
    Join Date
    Feb 2013
    Posts
    23

    Re: Very simple recursive algorithm

    something like that?
    Code:
    void cntZeros(int *a, int len, int *cnt, int* index){ 
         if(a[index]==0) *cnt++;
         index++;
         if(*index<len)cntZeros(a, len, cnt, index);
         return;
    }
    Last edited by BioPhysEngr; February 15th, 2013 at 07:26 PM. Reason: add code tags

  7. #7
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,006

    Re: Very simple recursive algorithm

    Welcome to the forum and thanks for your constructive comment. That will work, of course, but perhaps we are subtly suggesting he give the problem a try himself. :-) [But it's fine that you responded!]

    Also! A helpful forum trick: if you surround your code with [code] and [/code] blocks, it will preserve formatting. I've modified your post to show you how it woks.
    Best Regards,

    BioPhysEngr
    http://blog.biophysengr.net
    --
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center