I'm trying to generate the powerset of a set and I wrote this code. The problem is, when user enter two similar member of the set it dosen't work properly. What can I do? Here is my code:
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
using namespace std;
char obtain(char *p,int n)
{
int i;
for(i=0;i<n;i++)
{
cout<<"enter member"<<(i+1)<<"\n";
cin>>*(p+i);
}
return *p;
}
void set_display(char *p,int n)
{
cout<<"{";
for(int i=0;i<n;i++)
{
cout<<*(p+i)<<",";
}
cout<<"}";
}
void powset(char *p,int n)
{
unsigned int m = (double)pow((double)2, n);
int i, j;
for(i = 0; i < m; i++)
{
cout<<"{";
for(j = 0; j < n; j++)
{
if(i& (1<<j))
cout<<*(p+j);
}
cout<<"}\n";
}
}
cout
which is not defined in C or C#? – Inchstd::transform
which can be used to "transform" all members of a collection. – Greshamprintf
andstd::cout
. Use one or the other. – Greshamprintf
andcout
is probably indicative of sloppy coding, but why never?sync_with_stdio
exists for a reason right? And for instance, a quick search says this disagrees. – Blubberheadstd::endl
thenstd::cout
is faster. – Greshamsnprintf
...), but yours seemed to be more of a moral objection, the stress on never implying not just "I can't think of a good reason", but "There never can be a good reason". Maybe I just read too much into it. – Blubberhead