SlideShare a Scribd company logo
// Program to print all combination of size r in an array of size n
#include
void combinationUtil(int arr[], int data[], int start, int end,
int index, int r);
// The main function that prints all combinations of size r
// in arr[] of size n. This function mainly uses combinationUtil()
void printCombination(int arr[], int n, int r)
{
// A temporary array to store all combination one by one
int data[r];
// Print all combination using temprary array 'data[]'
combinationUtil(arr, data, 0, n-1, 0, r);
}
/* arr[] ---> Input Array
data[] ---> Temporary array to store current combination
start & end ---> Staring and Ending indexes in arr[]
index ---> Current index in data[]
r ---> Size of a combination to be printed */
void combinationUtil(int arr[], int data[], int start, int end,
int index, int r)
{
// Current combination is ready to be printed, print it
if (index == r)
{
if (data[0]+data[1]+data[2]+data[3]==24)
{
for (int j=0; j= r-index" makes sure that including one element
// at index will make a combination with remaining elements
// at remaining positions
for (int i=start; i<=end && end-i+1 >= r-index; i++)
{
data[index] = arr[i];
combinationUtil(arr, data, i+1, end, index+1, r);
}
}
// Driver program to test above functions
int main()
{
int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
int r = 4;
int n = sizeof(arr)/sizeof(arr[0]);
printCombination(arr, n, r);
}
Solution
// Program to print all combination of size r in an array of size n
#include
void combinationUtil(int arr[], int data[], int start, int end,
int index, int r);
// The main function that prints all combinations of size r
// in arr[] of size n. This function mainly uses combinationUtil()
void printCombination(int arr[], int n, int r)
{
// A temporary array to store all combination one by one
int data[r];
// Print all combination using temprary array 'data[]'
combinationUtil(arr, data, 0, n-1, 0, r);
}
/* arr[] ---> Input Array
data[] ---> Temporary array to store current combination
start & end ---> Staring and Ending indexes in arr[]
index ---> Current index in data[]
r ---> Size of a combination to be printed */
void combinationUtil(int arr[], int data[], int start, int end,
int index, int r)
{
// Current combination is ready to be printed, print it
if (index == r)
{
if (data[0]+data[1]+data[2]+data[3]==24)
{
for (int j=0; j= r-index" makes sure that including one element
// at index will make a combination with remaining elements
// at remaining positions
for (int i=start; i<=end && end-i+1 >= r-index; i++)
{
data[index] = arr[i];
combinationUtil(arr, data, i+1, end, index+1, r);
}
}
// Driver program to test above functions
int main()
{
int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
int r = 4;
int n = sizeof(arr)/sizeof(arr[0]);
printCombination(arr, n, r);
}

More Related Content

Similar to Program to print all combination of size r in an array of size n.pdf

5 array
5 array5 array
write a program that given a list of 20 integers, sorts them accordi.pdf
write a program that given a list of 20 integers, sorts them accordi.pdfwrite a program that given a list of 20 integers, sorts them accordi.pdf
write a program that given a list of 20 integers, sorts them accordi.pdf
armcomputers
 
c++ program I need to sort arrays using an insertion sort and a mer.pdf
c++ program I need to sort arrays using an insertion sort and a mer.pdfc++ program I need to sort arrays using an insertion sort and a mer.pdf
c++ program I need to sort arrays using an insertion sort and a mer.pdf
dhavalbl38
 
For this homework, you will write a program to create and manipulate.pdf
For this homework, you will write a program to create and manipulate.pdfFor this homework, you will write a program to create and manipulate.pdf
For this homework, you will write a program to create and manipulate.pdf
herminaherman
 
The language is C. Thanks. Write a function that computes the intege.pdf
The language is C. Thanks. Write a function that computes the intege.pdfThe language is C. Thanks. Write a function that computes the intege.pdf
The language is C. Thanks. Write a function that computes the intege.pdf
forwardcom41
 
Can you give an example of a binary heap programCan you give an .pdf
Can you give an example of a binary heap programCan you give an .pdfCan you give an example of a binary heap programCan you give an .pdf
Can you give an example of a binary heap programCan you give an .pdf
arorasales234
 
Need this in JAVA We have N numbers as an array, you need to find a .pdf
Need this in JAVA We have N numbers as an array, you need to find a .pdfNeed this in JAVA We have N numbers as an array, you need to find a .pdf
Need this in JAVA We have N numbers as an array, you need to find a .pdf
arorastores
 
There are a number of errors in the following program- All errors are.docx
There are a number of errors in the following program- All errors are.docxThere are a number of errors in the following program- All errors are.docx
There are a number of errors in the following program- All errors are.docx
clarkjanyce
 
Write a program in C that generates a list of random numbers greater.pdf
Write a program in C that generates a list of random numbers greater.pdfWrite a program in C that generates a list of random numbers greater.pdf
Write a program in C that generates a list of random numbers greater.pdf
arpitcomputronics
 
(Parent reference for BST) Redefine TreeNode by adding a reference to.pdf
(Parent reference for BST) Redefine TreeNode by adding a reference to.pdf(Parent reference for BST) Redefine TreeNode by adding a reference to.pdf
(Parent reference for BST) Redefine TreeNode by adding a reference to.pdf
arihantelehyb
 
Part 1)#include stdio.h #include stdlib.h #include pthrea.pdf
Part 1)#include stdio.h #include stdlib.h #include pthrea.pdfPart 1)#include stdio.h #include stdlib.h #include pthrea.pdf
Part 1)#include stdio.h #include stdlib.h #include pthrea.pdf
mohammadirfan136964
 
Digits.javapackage week04;import java.util.Scanner; public cla.pdf
Digits.javapackage week04;import java.util.Scanner; public cla.pdfDigits.javapackage week04;import java.util.Scanner; public cla.pdf
Digits.javapackage week04;import java.util.Scanner; public cla.pdf
annapurnnatextailes
 
IN C CODEGiven an IntNode struct and the operating functions for a.pdf
IN C CODEGiven an IntNode struct and the operating functions for a.pdfIN C CODEGiven an IntNode struct and the operating functions for a.pdf
IN C CODEGiven an IntNode struct and the operating functions for a.pdf
siva009113
 
I have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfI have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdf
shreeaadithyaacellso
 
Embedded C - Lecture 2
Embedded C - Lecture 2Embedded C - Lecture 2
Embedded C - Lecture 2
Mohamed Abdallah
 
Write a program that reads in integer as many as the user enters from.docx
Write a program that reads in integer as many as the user enters from.docxWrite a program that reads in integer as many as the user enters from.docx
Write a program that reads in integer as many as the user enters from.docx
lez31palka
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2
YOGESH SINGH
 
Given an IntNode struct and the operating functions for a linked list-.pdf
Given an IntNode struct and the operating functions for a linked list-.pdfGiven an IntNode struct and the operating functions for a linked list-.pdf
Given an IntNode struct and the operating functions for a linked list-.pdf
NicholasflqStewartl
 
Arrays
ArraysArrays
Arrays
fahadshakeel
 
Here is the code- I can't get it to work- I need a function that finds.pdf
Here is the code- I can't get it to work- I need a function that finds.pdfHere is the code- I can't get it to work- I need a function that finds.pdf
Here is the code- I can't get it to work- I need a function that finds.pdf
doshirajesh75
 

Similar to Program to print all combination of size r in an array of size n.pdf (20)

5 array
5 array5 array
5 array
 
write a program that given a list of 20 integers, sorts them accordi.pdf
write a program that given a list of 20 integers, sorts them accordi.pdfwrite a program that given a list of 20 integers, sorts them accordi.pdf
write a program that given a list of 20 integers, sorts them accordi.pdf
 
c++ program I need to sort arrays using an insertion sort and a mer.pdf
c++ program I need to sort arrays using an insertion sort and a mer.pdfc++ program I need to sort arrays using an insertion sort and a mer.pdf
c++ program I need to sort arrays using an insertion sort and a mer.pdf
 
For this homework, you will write a program to create and manipulate.pdf
For this homework, you will write a program to create and manipulate.pdfFor this homework, you will write a program to create and manipulate.pdf
For this homework, you will write a program to create and manipulate.pdf
 
The language is C. Thanks. Write a function that computes the intege.pdf
The language is C. Thanks. Write a function that computes the intege.pdfThe language is C. Thanks. Write a function that computes the intege.pdf
The language is C. Thanks. Write a function that computes the intege.pdf
 
Can you give an example of a binary heap programCan you give an .pdf
Can you give an example of a binary heap programCan you give an .pdfCan you give an example of a binary heap programCan you give an .pdf
Can you give an example of a binary heap programCan you give an .pdf
 
Need this in JAVA We have N numbers as an array, you need to find a .pdf
Need this in JAVA We have N numbers as an array, you need to find a .pdfNeed this in JAVA We have N numbers as an array, you need to find a .pdf
Need this in JAVA We have N numbers as an array, you need to find a .pdf
 
There are a number of errors in the following program- All errors are.docx
There are a number of errors in the following program- All errors are.docxThere are a number of errors in the following program- All errors are.docx
There are a number of errors in the following program- All errors are.docx
 
Write a program in C that generates a list of random numbers greater.pdf
Write a program in C that generates a list of random numbers greater.pdfWrite a program in C that generates a list of random numbers greater.pdf
Write a program in C that generates a list of random numbers greater.pdf
 
(Parent reference for BST) Redefine TreeNode by adding a reference to.pdf
(Parent reference for BST) Redefine TreeNode by adding a reference to.pdf(Parent reference for BST) Redefine TreeNode by adding a reference to.pdf
(Parent reference for BST) Redefine TreeNode by adding a reference to.pdf
 
Part 1)#include stdio.h #include stdlib.h #include pthrea.pdf
Part 1)#include stdio.h #include stdlib.h #include pthrea.pdfPart 1)#include stdio.h #include stdlib.h #include pthrea.pdf
Part 1)#include stdio.h #include stdlib.h #include pthrea.pdf
 
Digits.javapackage week04;import java.util.Scanner; public cla.pdf
Digits.javapackage week04;import java.util.Scanner; public cla.pdfDigits.javapackage week04;import java.util.Scanner; public cla.pdf
Digits.javapackage week04;import java.util.Scanner; public cla.pdf
 
IN C CODEGiven an IntNode struct and the operating functions for a.pdf
IN C CODEGiven an IntNode struct and the operating functions for a.pdfIN C CODEGiven an IntNode struct and the operating functions for a.pdf
IN C CODEGiven an IntNode struct and the operating functions for a.pdf
 
I have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfI have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdf
 
Embedded C - Lecture 2
Embedded C - Lecture 2Embedded C - Lecture 2
Embedded C - Lecture 2
 
Write a program that reads in integer as many as the user enters from.docx
Write a program that reads in integer as many as the user enters from.docxWrite a program that reads in integer as many as the user enters from.docx
Write a program that reads in integer as many as the user enters from.docx
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2
 
Given an IntNode struct and the operating functions for a linked list-.pdf
Given an IntNode struct and the operating functions for a linked list-.pdfGiven an IntNode struct and the operating functions for a linked list-.pdf
Given an IntNode struct and the operating functions for a linked list-.pdf
 
Arrays
ArraysArrays
Arrays
 
Here is the code- I can't get it to work- I need a function that finds.pdf
Here is the code- I can't get it to work- I need a function that finds.pdfHere is the code- I can't get it to work- I need a function that finds.pdf
Here is the code- I can't get it to work- I need a function that finds.pdf
 

More from info518726

HeadPhone.java All the outputs were same because the variabl.pdf
 HeadPhone.java  All the outputs were same because the variabl.pdf HeadPhone.java  All the outputs were same because the variabl.pdf
HeadPhone.java All the outputs were same because the variabl.pdf
info518726
 
Methanol is soluble in water. methanol is a one carbon organic alco.pdf
  Methanol is soluble in water.  methanol is a one carbon organic alco.pdf  Methanol is soluble in water.  methanol is a one carbon organic alco.pdf
Methanol is soluble in water. methanol is a one carbon organic alco.pdf
info518726
 
Solubility in water happens when something is pol.pdf
                     Solubility in water happens when something is pol.pdf                     Solubility in water happens when something is pol.pdf
Solubility in water happens when something is pol.pdf
info518726
 
moles = 0.144 .pdf
                     moles = 0.144                                    .pdf                     moles = 0.144                                    .pdf
moles = 0.144 .pdf
info518726
 
It is used to remove water from the organic layer.pdf
                     It is used to remove water from the organic layer.pdf                     It is used to remove water from the organic layer.pdf
It is used to remove water from the organic layer.pdf
info518726
 
nitrogen is more electronegative than phosphorus .pdf
                     nitrogen is more electronegative than phosphorus .pdf                     nitrogen is more electronegative than phosphorus .pdf
nitrogen is more electronegative than phosphorus .pdf
info518726
 
ionic equation is 2 Cu+2(aq) + 4Cl-(aq) + 4 K+(aq.pdf
                     ionic equation is 2 Cu+2(aq) + 4Cl-(aq) + 4 K+(aq.pdf                     ionic equation is 2 Cu+2(aq) + 4Cl-(aq) + 4 K+(aq.pdf
ionic equation is 2 Cu+2(aq) + 4Cl-(aq) + 4 K+(aq.pdf
info518726
 
hydration of alkene. .pdf
                     hydration of alkene.                             .pdf                     hydration of alkene.                             .pdf
hydration of alkene. .pdf
info518726
 
H2O + NO + NO2 -- 2HNO2 Three molecules collide.pdf
                     H2O + NO + NO2 -- 2HNO2  Three molecules collide.pdf                     H2O + NO + NO2 -- 2HNO2  Three molecules collide.pdf
H2O + NO + NO2 -- 2HNO2 Three molecules collide.pdf
info518726
 
he coordination compounds , metal complexes or si.pdf
                     he coordination compounds , metal complexes or si.pdf                     he coordination compounds , metal complexes or si.pdf
he coordination compounds , metal complexes or si.pdf
info518726
 
PdCl2 + 2DMSO PdCl22DMSO It forms a complexe..pdf
                     PdCl2 + 2DMSO  PdCl22DMSO  It forms a complexe..pdf                     PdCl2 + 2DMSO  PdCl22DMSO  It forms a complexe..pdf
PdCl2 + 2DMSO PdCl22DMSO It forms a complexe..pdf
info518726
 
melting point of the mixture decreases when small.pdf
                     melting point of the mixture decreases when small.pdf                     melting point of the mixture decreases when small.pdf
melting point of the mixture decreases when small.pdf
info518726
 
  Polymers are made by joining small molecules into large ones.But m.pdf
  Polymers are made by joining small molecules into large ones.But m.pdf  Polymers are made by joining small molecules into large ones.But m.pdf
  Polymers are made by joining small molecules into large ones.But m.pdf
info518726
 
What is Operational ExcellenceAchieving Operational Excellence requ.pdf
What is Operational ExcellenceAchieving Operational Excellence requ.pdfWhat is Operational ExcellenceAchieving Operational Excellence requ.pdf
What is Operational ExcellenceAchieving Operational Excellence requ.pdf
info518726
 
the name arsenic acid, like phosphoric acid (H3PO4), does notconvey .pdf
the name arsenic acid, like phosphoric acid (H3PO4), does notconvey .pdfthe name arsenic acid, like phosphoric acid (H3PO4), does notconvey .pdf
the name arsenic acid, like phosphoric acid (H3PO4), does notconvey .pdf
info518726
 
Sucrose is a molecular compound and does not ionize in solution.KC.pdf
Sucrose is a molecular compound and does not ionize in solution.KC.pdfSucrose is a molecular compound and does not ionize in solution.KC.pdf
Sucrose is a molecular compound and does not ionize in solution.KC.pdf
info518726
 
C. Increasing the temperature of the system .pdf
                     C. Increasing the temperature of the system      .pdf                     C. Increasing the temperature of the system      .pdf
C. Increasing the temperature of the system .pdf
info518726
 
because Electron Affinity is the amount of energy.pdf
                     because Electron Affinity is the amount of energy.pdf                     because Electron Affinity is the amount of energy.pdf
because Electron Affinity is the amount of energy.pdf
info518726
 
Ques-1Clostredium botulinum, bacteria that cause food poisoning &.pdf
Ques-1Clostredium botulinum, bacteria that cause food poisoning &.pdfQues-1Clostredium botulinum, bacteria that cause food poisoning &.pdf
Ques-1Clostredium botulinum, bacteria that cause food poisoning &.pdf
info518726
 
Programprinting.c#include stdio.hint main() {    cha.pdf
Programprinting.c#include stdio.hint main() {    cha.pdfProgramprinting.c#include stdio.hint main() {    cha.pdf
Programprinting.c#include stdio.hint main() {    cha.pdf
info518726
 

More from info518726 (20)

HeadPhone.java All the outputs were same because the variabl.pdf
 HeadPhone.java  All the outputs were same because the variabl.pdf HeadPhone.java  All the outputs were same because the variabl.pdf
HeadPhone.java All the outputs were same because the variabl.pdf
 
Methanol is soluble in water. methanol is a one carbon organic alco.pdf
  Methanol is soluble in water.  methanol is a one carbon organic alco.pdf  Methanol is soluble in water.  methanol is a one carbon organic alco.pdf
Methanol is soluble in water. methanol is a one carbon organic alco.pdf
 
Solubility in water happens when something is pol.pdf
                     Solubility in water happens when something is pol.pdf                     Solubility in water happens when something is pol.pdf
Solubility in water happens when something is pol.pdf
 
moles = 0.144 .pdf
                     moles = 0.144                                    .pdf                     moles = 0.144                                    .pdf
moles = 0.144 .pdf
 
It is used to remove water from the organic layer.pdf
                     It is used to remove water from the organic layer.pdf                     It is used to remove water from the organic layer.pdf
It is used to remove water from the organic layer.pdf
 
nitrogen is more electronegative than phosphorus .pdf
                     nitrogen is more electronegative than phosphorus .pdf                     nitrogen is more electronegative than phosphorus .pdf
nitrogen is more electronegative than phosphorus .pdf
 
ionic equation is 2 Cu+2(aq) + 4Cl-(aq) + 4 K+(aq.pdf
                     ionic equation is 2 Cu+2(aq) + 4Cl-(aq) + 4 K+(aq.pdf                     ionic equation is 2 Cu+2(aq) + 4Cl-(aq) + 4 K+(aq.pdf
ionic equation is 2 Cu+2(aq) + 4Cl-(aq) + 4 K+(aq.pdf
 
hydration of alkene. .pdf
                     hydration of alkene.                             .pdf                     hydration of alkene.                             .pdf
hydration of alkene. .pdf
 
H2O + NO + NO2 -- 2HNO2 Three molecules collide.pdf
                     H2O + NO + NO2 -- 2HNO2  Three molecules collide.pdf                     H2O + NO + NO2 -- 2HNO2  Three molecules collide.pdf
H2O + NO + NO2 -- 2HNO2 Three molecules collide.pdf
 
he coordination compounds , metal complexes or si.pdf
                     he coordination compounds , metal complexes or si.pdf                     he coordination compounds , metal complexes or si.pdf
he coordination compounds , metal complexes or si.pdf
 
PdCl2 + 2DMSO PdCl22DMSO It forms a complexe..pdf
                     PdCl2 + 2DMSO  PdCl22DMSO  It forms a complexe..pdf                     PdCl2 + 2DMSO  PdCl22DMSO  It forms a complexe..pdf
PdCl2 + 2DMSO PdCl22DMSO It forms a complexe..pdf
 
melting point of the mixture decreases when small.pdf
                     melting point of the mixture decreases when small.pdf                     melting point of the mixture decreases when small.pdf
melting point of the mixture decreases when small.pdf
 
  Polymers are made by joining small molecules into large ones.But m.pdf
  Polymers are made by joining small molecules into large ones.But m.pdf  Polymers are made by joining small molecules into large ones.But m.pdf
  Polymers are made by joining small molecules into large ones.But m.pdf
 
What is Operational ExcellenceAchieving Operational Excellence requ.pdf
What is Operational ExcellenceAchieving Operational Excellence requ.pdfWhat is Operational ExcellenceAchieving Operational Excellence requ.pdf
What is Operational ExcellenceAchieving Operational Excellence requ.pdf
 
the name arsenic acid, like phosphoric acid (H3PO4), does notconvey .pdf
the name arsenic acid, like phosphoric acid (H3PO4), does notconvey .pdfthe name arsenic acid, like phosphoric acid (H3PO4), does notconvey .pdf
the name arsenic acid, like phosphoric acid (H3PO4), does notconvey .pdf
 
Sucrose is a molecular compound and does not ionize in solution.KC.pdf
Sucrose is a molecular compound and does not ionize in solution.KC.pdfSucrose is a molecular compound and does not ionize in solution.KC.pdf
Sucrose is a molecular compound and does not ionize in solution.KC.pdf
 
C. Increasing the temperature of the system .pdf
                     C. Increasing the temperature of the system      .pdf                     C. Increasing the temperature of the system      .pdf
C. Increasing the temperature of the system .pdf
 
because Electron Affinity is the amount of energy.pdf
                     because Electron Affinity is the amount of energy.pdf                     because Electron Affinity is the amount of energy.pdf
because Electron Affinity is the amount of energy.pdf
 
Ques-1Clostredium botulinum, bacteria that cause food poisoning &.pdf
Ques-1Clostredium botulinum, bacteria that cause food poisoning &.pdfQues-1Clostredium botulinum, bacteria that cause food poisoning &.pdf
Ques-1Clostredium botulinum, bacteria that cause food poisoning &.pdf
 
Programprinting.c#include stdio.hint main() {    cha.pdf
Programprinting.c#include stdio.hint main() {    cha.pdfProgramprinting.c#include stdio.hint main() {    cha.pdf
Programprinting.c#include stdio.hint main() {    cha.pdf
 

Recently uploaded

How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5
sayalidalavi006
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 

Recently uploaded (20)

How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 

Program to print all combination of size r in an array of size n.pdf

  • 1. // Program to print all combination of size r in an array of size n #include void combinationUtil(int arr[], int data[], int start, int end, int index, int r); // The main function that prints all combinations of size r // in arr[] of size n. This function mainly uses combinationUtil() void printCombination(int arr[], int n, int r) { // A temporary array to store all combination one by one int data[r]; // Print all combination using temprary array 'data[]' combinationUtil(arr, data, 0, n-1, 0, r); } /* arr[] ---> Input Array data[] ---> Temporary array to store current combination start & end ---> Staring and Ending indexes in arr[] index ---> Current index in data[] r ---> Size of a combination to be printed */ void combinationUtil(int arr[], int data[], int start, int end, int index, int r) { // Current combination is ready to be printed, print it if (index == r) { if (data[0]+data[1]+data[2]+data[3]==24) { for (int j=0; j= r-index" makes sure that including one element // at index will make a combination with remaining elements // at remaining positions for (int i=start; i<=end && end-i+1 >= r-index; i++) { data[index] = arr[i]; combinationUtil(arr, data, i+1, end, index+1, r); } }
  • 2. // Driver program to test above functions int main() { int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; int r = 4; int n = sizeof(arr)/sizeof(arr[0]); printCombination(arr, n, r); } Solution // Program to print all combination of size r in an array of size n #include void combinationUtil(int arr[], int data[], int start, int end, int index, int r); // The main function that prints all combinations of size r // in arr[] of size n. This function mainly uses combinationUtil() void printCombination(int arr[], int n, int r) { // A temporary array to store all combination one by one int data[r]; // Print all combination using temprary array 'data[]' combinationUtil(arr, data, 0, n-1, 0, r); } /* arr[] ---> Input Array data[] ---> Temporary array to store current combination start & end ---> Staring and Ending indexes in arr[] index ---> Current index in data[] r ---> Size of a combination to be printed */ void combinationUtil(int arr[], int data[], int start, int end, int index, int r) { // Current combination is ready to be printed, print it if (index == r) { if (data[0]+data[1]+data[2]+data[3]==24)
  • 3. { for (int j=0; j= r-index" makes sure that including one element // at index will make a combination with remaining elements // at remaining positions for (int i=start; i<=end && end-i+1 >= r-index; i++) { data[index] = arr[i]; combinationUtil(arr, data, i+1, end, index+1, r); } } // Driver program to test above functions int main() { int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; int r = 4; int n = sizeof(arr)/sizeof(arr[0]); printCombination(arr, n, r); }