Tech
Forums
Jobs
Books
Events
Videos
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
1
Answer
Help me to rewrite my code below in C++?
Joe Wilson
10y
886
1
Reply
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();
}
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
Graph from layout table user input
Retrieve files from a folders for the specified datetime ran