Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9029919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:21:47+00:00 2026-06-16T07:21:47+00:00

I have a listbox where users can enter decimal numbers. Let’s say they’ll enter

  • 0

I have a listbox where users can enter decimal numbers. Let’s say they’ll enter 5 numbers:

1.1
1.2
1.3
1.4 
1.5

I need to get the sum of all the variations in those 5 numbers. For example sum of 1.1 and 1.2 then 1.1 1.2 1.3 then 1.1 1.2 1.3 1.4, then 1.2 1.4 1.5 then 1.1 1.3 1.5.

I started something but that goes through all the variations only skipping one number at a time:

List<Double[]> listNumber = new List<double[]>();            
Double[] array;            
for (int i = 0; i < listBox1.Items.Count; i++)
{
    array = new Double[listBox1.Items.Count];                
    for (int k = 0; k < listBox1.Items.Count; k++)
    {
        if (!k.Equals(i))
        {
            array[k] = (Convert.ToDouble(listBox1.Items[k]));                       
        }
    }
    listNumber.Add(array);
}   

I need to find a way how to calculate the way I want.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T07:21:48+00:00Added an answer on June 16, 2026 at 7:21 am

    In your initial attempt, your code only calculates the sum of all possible pairs. From your description, you also want to find the sum of three numbers, etc..

    If there are always 5 decimal numbers, then you can simply have 5 for loops. However a more generic design would be cleaner

    double[] input = double[5]; //Pretend the user has entered these
    int[] counters = int[input.Length]; //One for each "dimension"
    List<double> sums = new List<double>();
    
    for (int i = 0; i < counters.Length; i++)
       counters[i] = -1; //The -1 value allows the process to begin with sum of single digits, then pairs, etc..
    
    while (true)
    {
        double thisSum = 0;
        //Apply counters
        for (int i = 0; i < counters.Length; i++)
        {
            if (counters[i] == -1) continue; 
    
            thisSum += input[counters[i]];
        }
    
        //Increment counters
        counters[0]++; //Increment at base
        for (int i = 0; i < counters.Length; i++)
        {
            if (counters[i] >= counters.Length)
            {
                if (i == counters.Length - 1) //Check if this is the last dimension
                   return sums; //Exhausted all possible combinations
    
                counters[i] = 0;
                counters[i+1]++;
            }
            else
               break;
        }
    }
    

    Here it is without any code for avoiding the addition of the same number twice (I’ll let you try to finish that off. HINT: You can simply do so after the increment counters section, containing both the “Increment Counters” section and the new “Check Counters” section inside a while loop, breaking outside the while loop when the counters are unique…

    NOTE: I haven’t tested this code, but it’ll be close, and will likely have one or two bugs in it – let me know if you need any help with the bugs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a listbox that you can select users in. To the left of
My users can't seem to deselect all on a select in html. I have
I have a listbox that users can add/remove from. To add, there's a text
I have a listbox containing Users. The datasource is an generic list of the
I have a Listbox where all cells are editable. While the user is typing
I have a ListBox and I need to repeat the styles to be the
I have a Listbox that allows user to select multiple items. Normally user can
I have ListBox data bind to list of users (collection): usersListBox.DataSource = null; usersListBox.DataSource
I have two listbox's. One is filled by Users. daUsers = new SqlDataAdapter(SELECT *
When a Xul's listbox have more itens than it can show, the doc says

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.