none
how to generate probability table RRS feed

  • Question

  • Hi there,

    Here i want to ask about how to generate probability table according to my custom request ,for example if i enter (2) then it generates 

    A  B

    0  0

    0  1

    1  0

    1  1

    i have a research and i want this part of code importantly.

    Thanks


    Esmat

    Tuesday, April 2, 2019 12:32 PM

Answers

  • Hi there,

    Here i want to ask about how to generate probability table according to my custom request ,for example if i enter (2) then it generates 

    A  B

    0  0

    0  1

    1  0

    1  1

    i have a research and i want this part of code importantly.

    Thanks


    Esmat

    Hi     Esmat_Halfa,

     Thank you for posting here. Based on your question, I make an example:

      Console.WriteLine("Please enter an integer\n");
                int m = int.Parse(Console.ReadLine());
                StringBuilder A = new StringBuilder();
                for (int i=0;i<m;i++)
                {
                    A.Append(("C" + i + " "));
                }
                Console.WriteLine(A);
    
                int number, maxNumber = 0;
                for (int i=0;i<m;i++)
                {
                    maxNumber += (int)Math.Pow(2, i);
                }
                
                for (int everyNumber=0;everyNumber<=maxNumber;everyNumber++)
                {
                    int[] a = new int[m];
                    number = everyNumber;
                    StringBuilder s = new StringBuilder();
    
                   for (int i = 0; i < m; i++)  
                    {
                        a[i] = number % 2;        
                        number = number / 2;
                    }
                    for (int i = m - 1; i >= 0; i--)
                    {
                        s.Append(a[i] + "  ");
                    }
                    Console.WriteLine(s);  
                }
    

      Due to the limited number of A,B,C… I replaced them with C0,C1,C2 and so on.

      One of the results is shown below:

    Best Regards

    Yong Lu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Esmat_Halfa Friday, April 5, 2019 6:05 AM
    Wednesday, April 3, 2019 8:59 AM
    Moderator