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
Under which menu option of a word processing program does a callout appear?
Juli2301 [7.4K]
A callout is a type of text box that also includes a line for pointing to any location on the document. A callout appears under the SHAPES <span>menu of the word processing program. The answer that completes this statement is the word "shapes". Hope this answers your question. </span>
7 0
3 years ago
Prompt the user to input an integer, a double, a character, and a string, storing each into separate variables. Then, output tho
kotegsom [21]

Answer:

import java.util.Scanner;

public class ANot {

   public static void main(String[] args) {

Scanner in = new Scanner(System.in);

// Prompt user for an integer

       System.out.println("Please enter an Integer");

       int intNum = in.nextInt();

       // Prompt user for an double

       System.out.println("Please enter a double");

       double DoubleNum = in.nextDouble();

       // Prompt user for a character

       System.out.println("Please enter a Character");

       char charNum = in.next().charAt(0);

       // Prompt user for a String

       System.out.println("Please enter a String");

       String StringNum = in.next();

       System.out.println(intNum+" "+DoubleNum+" "+charNum+" "+StringNum);

   }

}

Explanation:

We import the Scanner class in order to receive user input. Then we create four different variables of type int, double,char and String to hold the values entered by the user.

To display the output on a single line, we use string concatenation (using the + operator) to acheive this.

6 0
3 years ago
Animal wisdom/ the last wolf .compare and contrast the overall feeling of each poem
masha68 [24]
List the poem please. I won’t be able to answer without it.
3 0
3 years ago
All digital images are made up from varying rectangles of color, called _____________.
Dmitry_Shevchenko [17]
<span>A Pixel (a word invented from "picture element") is the basic unit of programmable color on a computer display or in a computer image.</span>
4 0
3 years ago
Read 2 more answers
Following a company on likedin is most similar to
san4es73 [151]
Liking a company on Facebook
6 0
3 years ago
Other questions:
  • matlab Write a function that iteratively appends random 1's and 0's to an array to form a binary number. The function returns th
    9·1 answer
  • Jason is computer professional who has access to sensitive information. He shares this information with another organization in
    7·2 answers
  • if you could take on the role as game designer and could change or add some type of financial aspect about the game what would b
    6·1 answer
  • A virus enters a computer or network _____.
    13·1 answer
  • Which quality is likely to ensure consistent career growth in the computer field?
    9·2 answers
  • If classes C1 and C2 both implement an interface Cint, which has a method whichIsIt, and if C1 c = new C1( ); is performed at on
    15·1 answer
  • "Find the sum of the squares of the integers from 1 to MySquare, where MySquare is input by the user. Be sure to check that the
    9·1 answer
  • 7. What are the two keyboard keys you can press at the same time to use the Paste command? (1.0 points) Lesson 5 (5.0 points)
    13·1 answer
  • A _____ movement tries to improve a part of society, usually through legal methods.
    6·2 answers
  • Have you heard about Gold Opinions?<br><br> It is a new product that just came out.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!