Question

Objective: Help the students understand the basic operations on sets and also know the importance of choosing suitable data s
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>
#include<conio.h>
#define MAX 100
int printUnion (int arr1[], int arr2[], int m, int n)
{
int i = 0, j = 0;
while (i < m && j < n)
{
if (arr1[i] < arr2[j])
printf (" %d ", arr1[i++]);
else if (arr2[j] < arr1[i])
printf (" %d ", arr2[j++]);
else
   {
printf (" %d ", arr2[j++]);
i++;
}
}
/* Print remaining elements of the larger array */
while (i < m)
{
printf (" %d ", arr1[i++]);   
}
while (j < n)
{
printf (" %d ", arr2[j++]);
}
}
int printIntersection(int arr1[], int arr2[], int m, int n)
{
int i = 0, j = 0;
while (i < m && j < n)
{
if (arr1[i] < arr2[j])
i++;
else if (arr2[j] < arr1[i])
j++;
else /* if arr1[i] == arr2[j] */
{
printf(" %d ", arr2[j++]);
i++;
}
}
}
int findDifference(int arr1[], int arr2[], int m, int n)
{
int i=0,j=0,k=0,flag=0;
for(i=0;i<m;i++) //traverse 1st set element
{
for(j=0;j<n;j++) //traverse 1st set element
{
if(arr1[i]==arr2[j])
{
flag=0;
break;
}
else
{
flag=1;
}
}
if(flag==1)
{
printf("%d ",arr1[i]); //assign arr1 to arr3
k++;
}
}
}
int findCompliment(int arr1[],int arr2[],int m,int n)
{
int i=0,j=0,k=0,flag=0;
for(i=0;i<m;i++) //traverse 1st set element
{
for(j=0;j<n;j++) //traverse 1st set element
{
if(arr1[i]==arr2[j])
{
flag=0;
break;
}
else
{
flag=1;
}
}
if(flag==1)
{
printf("%d ",arr1[i]);
k++;
}
}   
}
/* Driver program to test above function */
int main ()
{
int U[MAX],A[MAX],B[MAX],C[MAX],D[MAX];
int p,q,r;
printf("Enter size of u");
scanf("%d",&p);
printf("Enter elements in u");
for(int i=0;i<p;i++)
{
scanf("%d",&U[i]);
}
printf("Enter size of A");
scanf("%d",&q);
printf("Enter elements of A");
for(int i=0;i<q;i++)
{
scanf("%d",&A[i]);
}
printf("Enter size of B");
scanf("%d",&r);
printf("Enter elements of B");
for(int i=0;i<r;i++)
{
scanf("%d",&B[i]);
}
printf("Union of {A,B}\n");
printUnion (A, B, q, r);
printf("\nIntersection of {A,B}\n");
printIntersection(A,B,q,r);
printf("\nDifference of {A,B}\n");
findDifference(A,B,q,r);
printf("\nfindCompliment of A\n");
findCompliment(U,A,p,q);
getch();
return 0;
}


output:

Enter size of u5
Enter elements in u1 3 5 7 9
Enter size of A2
Enter elements of A1 4
Enter size of B3
Enter elements of B1 5 6 9
Union of {A,B}
1 4 6 9
Intersection of {A,B}
1
Difference of {A,B}
4
findCompliment of A
3 5 7 9

Add a comment
Know the answer?
Add Answer to:
Objective: Help the students understand the basic operations on sets and also know the importance of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please I need help with this c++ code. please show all steps , write comments and...

    Please I need help with this c++ code. please show all steps , write comments and show sample runs. Thank you. 1. The Federal Bureau of Investigation (FBI) has recently changed its Universal Control Numbers (UCN) for identifying individuals who are in the FBI's fingerprint database to an eight-digit base 27 value with a ninth check digit. The digits used are: 0123456789ACDE FHJKLMNPRTVWX Some letters are not used because of possible confusion with other digits: B->8, G->C, I- >1, 0->0,...

  • help im alittle lost my teacher posted all this its suppose to be in C++ language....

    help im alittle lost my teacher posted all this its suppose to be in C++ language. can yoh leave comments ans type the code thank you Write a C++ program that accepts the lengths of three sides (a,b,c) of a triangle as input from the user Validate the user input, so that sides a, b, c can only be POSITIVE. The program output should indicate whether or not the triangle is an Equilateral Triangle, a Right Triangle, Isosceles which is...

  • i need summery of this Using Apple Technology to Support Learning for Students with Sensory and...

    i need summery of this Using Apple Technology to Support Learning for Students with Sensory and Learning Disabilities The science of learning seeks to understand the relationship between brain development, social interaction, and learning by drawing on the fields of psychology, neuroscience, machine learning, and education.1 This research holds great promise for improving our teaching practices for all students and helping us develop more effective approaches to teaching children with sensory and learning disabilities. Many of the universal design features...

  • C++ please Programming Assignment #6 Help Me Find The Secret Message Description: This assignment will require...

    C++ please Programming Assignment #6 Help Me Find The Secret Message Description: This assignment will require that you read in an encrypted message from a file, decode the message, and then output the message to a file. The encryption method being used on the file is called a shift cipher (Info Here). I will provide you with a sample encrypted message, the offset, and the decrypted message for testing. For this project I will provide you main.cpp, ShiftCipher.h, and ShiftCipher.cpp....

  • Plz help!! The programming language is C and could you write comments as well? Problem 2....

    Plz help!! The programming language is C and could you write comments as well? Problem 2. Calculate Grades (35 points) Arrays can be used for any data type, such as int and char. But they can also be used for complex data types like structs. Structs can be simple, containing simple data types, but they can also contain more complex data types, such as another struct. So you could have a struct inside of a struct. This problem deals with...

  • IN JAVA PLEASE HELP! ALSO PLEASE ADD COMMENTS Summary Build two classes (Fraction and Fraction Counter)...

    IN JAVA PLEASE HELP! ALSO PLEASE ADD COMMENTS Summary Build two classes (Fraction and Fraction Counter) and a Driver for use in counting the number of unique fractions read from a text file. We'll use the ArrayList class to store our list of unique Fraction Counters. Rather than designing a monolithic chunk of code in main like we did in the previous homework, we'll practice distributing our code into containers (called classes) that you will design specifically to tackle this...

  • 1 Overview The goal of this assignment is to help you understand caches better. You are...

    1 Overview The goal of this assignment is to help you understand caches better. You are required to write a cache simulator using the C programming language. The programs have to run on iLab machines. We are providing real program memory traces as input to your cache simulator. The format and structure of the memory traces are described below. We will not give you improperly formatted files. You can assume all your input files will be in proper format as...

  • Please, I need help with program c++. This is a chutes and ladders program. The code...

    Please, I need help with program c++. This is a chutes and ladders program. The code must be a novel code to the specifications of the problem statement. Thank you very much. Assignment Overview This program will implement a variation of the game “chutes and ladders” or “snakes and ladders:” https://en.wikipedia.org/wiki/Snakes_and_Ladders#Gameplay. Just like in the original game, landing on certain squares will jump the player ahead or behind. In this case, you are trying to reach to bottom of the...

  • This is my assignment prompt This is an example of the input and output This is...

    This is my assignment prompt This is an example of the input and output This is what I have so far What is the 3rd ToDo in the main.cpp for open the files and read the encrypted message? Does the rest of the code look accurate? Programming Assignment #6 Help Me Find The Secret Message Description: This assignment will require that you read in an encrypted message from a file, decode the message, and then output the message to a...

  • Java Programming The program template represents a complete working Java program with one or more key...

    Java Programming The program template represents a complete working Java program with one or more key lines of code replaced with comments. Read the problem description and examine the output, then study the template code. Using the problem-solving tips as a guide, replace the /* */ comments with Java code. Compile and execute the program. Compare your output with the sample output provided. Modify class Time2 to include a tick method that increments the time stored in a Time2 object...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT