none
Help for Convert C++ to C# code RRS feed

All replies

  • It's relatively straightforward to convert. Just a little tweaking of the data types and declarations, and of course changing printf int Console.WriteLine.

    using System;
    
    namespace ConsoleApplication1
    {
        class Example
        {
            const int MAX_ADDS = 100;
            const uint n = 15;
            const uint gN = 3;
    
            uint[] given = { 2, 3, 5 };
            uint[] mp = new uint[MAX_ADDS];
    
            void print(uint length)
            {
                uint i;
                for (i = 1; i < length; i++)
                    Console.WriteLine("{0} + ", mp[i]);
    
                Console.WriteLine("{0}\n", mp[length]);
            }
    
            void devNum(uint n, uint pos)
            {
                uint k, p;
                for (p = gN; p > 0; p--)
                {
                    k = given[p - 1];
                    if (n > k)
                    {
                        mp[pos] = k;
                        if (mp[pos] <= mp[pos - 1])
                            devNum(n - k, pos + 1);
                    }
                    else if (n == k)
                    {
                        mp[pos] = k;
                        if (mp[pos] <= mp[pos - 1])
                            print(pos);
                    }
                }
            }
    
            int Main()
            {
                mp[0] = n + 1;
                devNum(n, 1);
                return 0;
            }
        }
    }
    

    Saturday, March 24, 2018 12:23 PM
    Moderator
  • I solved it. Thanks anyway! 

    Saturday, March 24, 2018 2:29 PM
  • Hi rossirm,

    I realize that you're new here, so I thought it might be a good idea to explain how some things work on these forums. I hope you don't think I'm criticizing you, just trying to inform you.

    1. You should not have edited your first post to totally remove the question! What if other people were searching the forums for a similar problem? Now, no one has any idea what the question was to begin with.
    2. When you have solved the problem on your own, forum etiquette is to post what you ended up doing to solve your problem.
    3. And then, since you have posted the actual solution to your problem, you would mark your post containing that solution as the Answer.

    I hope that is helpful ...


    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Saturday, March 24, 2018 4:43 PM
    Moderator
  • And it is likely that Alberto's response did actually help. Beginners often do that kind of thing. I think there is at least one person that just creates a new identity for each new question so they have no incentive to obey the rules.


    Sam Hobbs
    SimpleSamples.Info

    Saturday, March 24, 2018 5:33 PM
  • I solved it. Thanks anyway! 

    Please refrain from editing your question for the reasons Bonnie mentioned. Nobody will benefit from this.

    Please edit your initial question if you can to what it was prior to your current edit.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Sunday, March 25, 2018 10:56 AM
    Moderator