473,396 Members | 2,057 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

show all subset of a sub

6
A program is a set of all subsets of this part of the show. Users can enter a number., For example, if n = 2 the output looks like this:
{}
{1}
{2}
{1,2}
or for n=3 we have:
{}
{1}
{2}
{3}
{1,2}
{1,3}
{2,3}
{1,2,3}
meantime this program should be solved with tow way.
recursive function and Non-recursive.Can also be used in solving the problem of bitwise operations.
Feb 6 '14 #1

✓ answered by Nepomuk

OK, so that's the task. What have you done so far? We won't do your homework for you but we're happy to help you solve it yourself.

2 1084
Nepomuk
3,112 Expert 2GB
OK, so that's the task. What have you done so far? We won't do your homework for you but we're happy to help you solve it yourself.
Feb 6 '14 #2
mmag
6
my algorithm that is for per subset exists one number. these numbers are form 0 until (2^n)-1.allow me explain it with a example.
n=3
{ } 000 0
{1} 100 4
{2} 010 2
{3} 001 1
{1,2} 110 6
{1,3} 101 5
{2,3} 011 3
{1,2,3} 111 7
The third column show some number(fn) that i use in code.now we know per number of subset has to state(sn).0 or 1. this means it exists or not exists.now i should match fn and sn. and suggested way is use of bitwise operators.(operator &).and now i don't know what do and thing with else thing.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3. #include <conio.h>
  4. #include <string.h>
  5. int pow(int a,int b)
  6. {
  7.     int p=1;
  8.     for(int i=0;i<b;i++)
  9.         p=p*a;
  10.     return p;
  11. }
  12. struct ar
  13. {
  14.     int  binary;
  15.     int content;
  16. };
  17. int main()
  18.  
  19. {
  20.     int testcase=0;
  21.     int n;
  22.     ar *a;
  23.     a=new ar [2000];
  24.     cin>>testcase;
  25.     int i=0;
  26.     while(i<testcase)
  27.     {
  28.         cin>>n;
  29.         for(int j=0,k=1;j<n;j++,k++)
  30.         {
  31.             a[j].content=k;
  32.             a[j].binary=2;
  33.         }
  34.  
  35.  
  36.     for(int p=0;p<pow(2,n)-1;p++)
  37.     {
  38.         cout<<'{';
  39.     for(int m=0;m<n;m++)
  40.     {
  41.  
  42.         int b;
  43.         b=a[m].binary&p;
  44.         if(b==1)
  45.         cout<<a[i].content<<' ';
  46.  
  47.     }
  48.       cout<<'}';
  49.     }
  50.  
  51.     cout<<endl;
  52.     i++;
  53.     }
  54.     return 0;
  55. }
Feb 6 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: les_ander | last post by:
Hi, I have many set objects some of which can contain same group of object while others can be subset of the other. Given a list of sets, I need to get a list of unique sets such that non of the...
5
by: Oliver Dain | last post by:
I've seen it asserted in a few places that C is not a proper subset of C++, but I don't understand the assertion. What things are valid C that aren't valid C++? Thanks.
29
by: Chris Dutrow | last post by:
I searched around on the net for a bit, couldn't find anything though. I would like to find some code for a function where I input A Range Of Integers For example: Function( 1, 100 ); And the...
2
by: Dave | last post by:
Hello all, I have a class that contains a large number of discrete pieces of state information. Any combination of these member variables might be valid for a given object. Any given member...
36
by: Robert Vazan | last post by:
I am looking for other people's attempts to create safe subset of C and enforce it with scripts. Does anybody know about anything like this? By "safe", I mean the following: * Strongly typed...
3
by: Carolyn Vo | last post by:
I have a datagrid in my web control class that I am trying to get the current rows displayed for. I have enabled paging on the datagrid so if the user is currently on page 3 of 8, and if I have...
4
by: Atley | last post by:
I am using VB.net Ent Arch 2003. I have a dataset that was made through the wizard to create a Windows Data Form I have a DataGrid to show/edit the table from my DataSet. I want to: Be...
8
by: PAPutzback | last post by:
How do I keep the form up.
3
by: H | last post by:
I have a dataset with Customers, Orders, and Items tables. It has datarelations set between Customers-Orders and Orders-Items It has foreignkeyconstraints with update/delete rules set to cascade...
5
by: Ronald S. Cook | last post by:
From my business tier (class) I get back an IQueryable<Penof data. Here is my client code that works fine: PenClass penClass = new PenClass(); IQueryable<Penpens = penClass.SelectPens(); ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.