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 6381637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:25:11+00:00 2026-05-25T02:25:11+00:00

I need an algorithm which generates all possible combination of a set number and

  • 0

I need an algorithm which generates all possible combination of a set number and output all of them onto Excel spreadsheet.

For example, with n = 5(1,2,3,4,5) and r = 2(created a small gui for this), it will generate all possible combinations and output them into excel spreadsheet like this…

1,2
1,3
1,4
...

The order in which it prints doesn’t matter. It can first print (5,1), then (1,2).
Can anyone show me how to do this?

Thank you very much.

  • 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-05-25T02:25:12+00:00Added an answer on May 25, 2026 at 2:25 am

    How about this code…

    Option Explicit
    
    Private c As Integer
    
    Sub test_print_nCr()
      print_nCr 5, 3, Range("A1")
    End Sub
    
    Function print_nCr(n As Integer, r As Integer, p As Range)
      c = 1
      internal_print_nCr n, r, p, 1, 1
    End Function
    
    
    Private Function internal_print_nCr(n As Integer, r As Integer, ByVal p As Range, Optional i As Integer, Optional l As Integer) As Integer
    
      ' n is the number of items we are choosing from
      ' r is the number of items to choose
      ' p is the upper corner of the output range
      ' i is the minimum item we are allowed to pick
      ' l is how many levels we are in to the choosing
      ' c is the complete set we are working on
    
      If n < 1 Or r > n Or r < 0 Then Err.Raise 1
      If i < 1 Then i = 1
      If l < 1 Then l = 1
      If c < 1 Then c = 1
      If r = 0 then 
        p = 1
        Exit Function
      End If
    
      Dim x As Integer
      Dim y As Integer
    
      For x = i To n - r + 1
        If r = 1 Then
          If c > 1 Then
            For y = 0 To l - 2
              If p.Offset(c - 1, y) = "" Then p.Offset(c - 1, y) = p.Offset(c - 2, y)
            Next
          End If
          p.Offset(c - 1, l - 1) = x
          c = c + 1
        Else
          p.Offset(c - 1, l - 1) = x
          internal_print_nCr n, r - 1, p, x + 1, l + 1
        End If
      Next
    
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need an algorithm which given a list L and a number N ,
I need to write generator which yield all possible 8 symbols strings. From array
I need help regarding DDA algorithm , i'm confused by the tutorial which i
I need an example algorithm that will draw pixels one at a time on
I have a set S of small trees S[i] which I need to find
I'm writing a Monte Carlo algorithm, in which at one point I need to
My problem is that I need for a graphical output of an algorithm a
I need an algorithm to determine if a sentence, paragraph or article is negative
I need the algorithm to animate the arrow based on 2 parameters, angle while
I need effective algorithm to keep only ten latest files on disk in particular

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.