Joe Wilson

Joe Wilson

  • NA
  • 7.8k
  • 418.3k

Help me to rewrite my code below in C++?

Sep 26 2014 8:18 AM
I mean I want to use cout and cin instead of printf and scanf by the way I want to ask user to choose the members(numbers) of set and the size of set then use my printsubset function.
 
 
This is my code:
 
#include < stdio.h>

#include < conio.h>

#define MAX 20

int set[MAX];

int flag[MAX];

void printsubset(int n)

{

int i;

printf("{");

for (i=0 ; i < n ; i++)

if (flag[i])

printf ("%d ",set[i]);

printf("}\n");

}

void subset(int n,int i)

{

if (i==n)

{

printsubset(n);

return;

}

flag[i]=1;

subset(n,i+1);

flag[i]=0;

subset(n,i+1);

}

main()

{

int n=4;

for (int i=0 ; i < n ; i++)

{

set[i]=i+1;

flag[i]=0;

}

subset(n,0);

getch();

 
 
 
 

Answers (1)