Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth
Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

42,753 questions

55,518 answers

573 users

How to generate 3 combinations of X numbers in C

1 Answer

0 votes
#include <stdio.h>
 
void Generate3CombinationOfXNumbers(int arr[], int size) {
    for (int i = 0; i < size; i++) {
        for (int j = i + 1; j < size; j++) {
            for (int k = j + 1; k < size; k++) {
                printf("%d %d %d\n", arr[i], arr[j], arr[k]);
            }
        }
    }
}
 
int main()
{
    int arr[] = { 1, 2, 3, 4, 5 };
    int size = sizeof(arr) / sizeof(arr[0]);
 
    Generate3CombinationOfXNumbers(arr, size);
 
    return 0;
}
 
 
 
/*
run:
 
1 2 3 
1 2 4 
1 2 5 
1 3 4 
1 3 5 
1 4 5 
2 3 4 
2 3 5 
2 4 5 
3 4 5 
 
*/

 



answered Sep 24, 2024 by avibootz

Related questions

1 answer 128 views
1 answer 129 views
1 answer 214 views
1 answer 265 views
1 answer 193 views
...