1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Katen [24]
3 years ago
8

Write an algorithm that prints out all the subsets of 3 elements of a set of n elements. The elements of the set are stored in a

list that is the input to the algorithm, (you may assume all elements in the list are distinct. The list can be an array). Algorithm: Print_3_Element_Subsets Input: List S of n distinct elements. Output: Print out all 3-element subsets of S. void Print_3_Element_Subsets (int n, const element_type S[])
Computers and Technology
1 answer:
Ksenya-84 [330]3 years ago
7 0

void Print_3_Element_Subsets(int n,const element_type S[])

{

if(n<3) // condition to check if list have less than 3 elements

{

print("No subset found");

}

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

{

for(int j =i+1; j < n ; j++)

{

for(int k =j+1; k < n ; k++)

{

print(S[i],S[j],S[k]);

}

}

}

}

C++ Implementation;

#include<cstdlib>

#include<time.h>

using namespace std;

int S1[5]= {1,2,3,4,5};

int n1 = 5;

int S2[2]={1,2};

int n2 = 2;

void Print_3_Element_Subsets(int n,const int S[])

{

if(n<3) // condition to check if list have less than 3 elements

{

printf("No subset found\n");

}

printf("3 Subsets are\n");

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

{

for(int j =i+1; j < n ; j++)

{

for(int k =j+1; k < n ; k++)

{

cout<<S[i]<<" "<<S[j]<<" "<<S[k]<<endl;

}

}

}

}

int main()

{

cout<<"Case 1"<<endl;

Print_3_Element_Subsets(n1,S1);

cout<<endl<<"Case 2"<<endl;

Print_3_Element_Subsets(n2,S2);

}

OUTPUT

Case 1

3 Subsets are

1 2 3

1 2 4

1 2 5

1 3 4

1 3 5

1 4 5

2 3 4

2 3 5

2 4 5

3 4 5

Case 2

No subset found

3 Subsets are

--------------------------------

Process exited after 0.0137 seconds with return value 0

Press any key to continue . . .

You might be interested in
What did Adam and Eve look like?
Nata [24]
No one could possibly know, unfortunately.
6 0
3 years ago
Read 2 more answers
Choose all items that represent HTML characteristics.
hram777 [196]

Answer:

A,C,D,E are the answers at least on the test i took

Explanation:

3 0
3 years ago
Read 2 more answers
What’s the purpose of balancing or monitoring your checking account?
emmasim [6.3K]
B) To help you calculate how much money you have in your account.
3 0
3 years ago
Read 2 more answers
What is the meaning of ethics? Check all of the boxes that apply
suter [353]

Answer:

behavior that is good for everyone

following the rules

behaving in a way that would be easy to defend

Explanation:

6 0
3 years ago
In addition to compiling the list of user access requirements, applications, and systems, the BIA also includes processes that a
laila [671]

Answer:

automated

Explanation:

Basically a Business Impact Analysis (BIA) estimates and determines the effects of a business activity and process disturbances. These disruptions can be natural or electronic disasters. It also collects information which is used to establish recovery plan. It identifies the business vulnerabilities and works on the strategies in order to reduce such potential hazards. The BIA involves both manual and automated processes. BIA involves automated processes which include the automated software tools that enables the protection of the confidential information of the users and also generates automated reports about the critical business processes.

5 0
3 years ago
Other questions:
  • What might a programming prefer the top-down approach to programming design?
    10·1 answer
  • If you are viewing a webpage with customized or regenerated content, such as updated stock quotes, what type of webpage are you
    14·1 answer
  • What is the full form of bcc please tell​
    15·2 answers
  • New Top Level Domains (TLDs) are coordinated by:_______.
    10·1 answer
  • Fill in the blank
    15·2 answers
  • Phil wants to make a dark themed superhero movie. What could be his target demographic
    11·2 answers
  • PLS HURRY<br> Look at the image below
    8·1 answer
  • Will this website ever get itself together to stop people from sending links?
    9·1 answer
  • When typing lists in a document, you must use single-spacing between each item in the list.
    8·1 answer
  • Goals of the project objectives
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!