How to write a program to find the union and intersection of two sets of integer store it in two array in C Programming Language ?
Solution:
/*write a program to find the union and intersection of two sets of integer store it in two array*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,n,b[10],k=0,inter[10],u[10];
int j,m;
clrscr();
printf("\nenter how many number :");
scanf("%d",&n);
printf("\nenter the number;");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\nenter the number;");
for(i=0;i<n;i++)
scanf("%d",&b[i]);
for(i=0;i<n;i++)
{
u[k]=a[i];
k++;
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(b[i]==a[j])
break;
}
if(j==n)
{
u[k]=b[i];
k++;
}
}
m=0;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(a[i]==b[j])
{
inter[m]=a[i];
m++;
}
}
}
printf("\nthe union is :");
for(i=0;i<k;i++)
{
printf("%d,",u[i]);
}
printf("\nthe intersection is :");
for(i=0;i<m;i++)
{
printf("%d,",inter[i]);
}
getch();
}
/*
enter how many number :4
enter the number;5
8
7
1
enter the number;9
6
5
4
the union is :5,8,7,1,9,6,4,
the intersection is :5,
*/
Learn More :
Integer
- How to Write a C program to perform basic math operations on two input whole numbers. The basic operations are addition, subtraction, multiplication, integer division, real division, and modulus.
- Sort Three Numbers - program reads in three Integers and displays them in ascending order.
- C program to Given a vector (integer or real), determine what is the maximum value of element what is the position in which this element is located
- C Program Generates 10 Random Integers Between 0 and 99.
- Lower-Upper Case/Positive-Negative Integer
- Give me an integer and I will sum it with the previous natural numbers
- C Program to Detect int Underflow-Overflow using if-else
- Menu Driven Program to Read Two Integers Find Sum, Difference and Product C Program
Find
- Find out the perfect number using c program
- Find g.c.d of two number using c program.
- Write a c program to find out NCR factor of given number
- How to Write a C program to find maximum between two numbers ?
- Write a C program to find maximum between three numbers ?
- C or C++ program to read marks of 4 subjects and find how many students are pass and fail with division
- C Program turnLEDOn to Drives Forward Until It Finds The Line
- Write overloaded function templates for finding the roots of the linear (a * x + b = 0) and square (a * x2 + b * x + c = 0) uravneniy.Zamechanie: in function to send coefficients of the equations.
- C Program to Find Random Number
- C Program To Find LCM and HCF Of Two Number Using Function - 2
- C Program to find LCM and HCF Of Two Number Using Recursion - 3
- C Program To Find LCM and HCF Of Two Number -1
- C Program To Find Length Of A String Including Blank Spaces, Tabs, And Other Special Characters
- C Program To Find Length Of String And Concatenate Two Strings
- C Program To Find Product Of Two No Using MACRO
- C Program To Find Reverse Of Any Digit Number
- C Program To Find Sum and Difference Of Two Matrices
- C Program To Find The Frequency Of A Number
- C Program To Find The Length, Reverse Of A String And To Check It Is Palindrome or Not
- C Program To Find The Maximum And Minimum Value In An Array
- C Program To Find Transpose Of A Matrix
- C Program To Find Union & Intersection Of Two Array
- C Program Finding the sum of Squares using Recursion
- C Program to Find NCR Of A Given Number Program
- C Program To Find Maximum Of Given Numbers
Array
- How to pass one dimensional array to function in c.
- Write a c program which passes two dimension array to function.
- C Program Array Index Example
- C Program Array Example: Average
- C Program Array Example: Reverse
- C Program Array Example
- C Program to Array
- C Program Array NxM Elements Geometric/Arithmetic
- C Program To Find The Maximum And Minimum Value In An Array
- C Program To Find Union & Intersection Of Two Array
- C Program To Search A Number Inside The Array
- C Program To Sort An Array In Ascending And Descending Order
- C Program To Sort An Array Of Names In Alphabetical And Reverse Order
- C Program To Copy One Character Array Into Another
- Returns: array of decoded values. [0] - count of values
- C Program to Check if a number is in an array[1000]
- C Program to Find max and min in array using pointer concept
- C Program Sort Array By Segment
- C Program to sort an array using bubble sort
- C Program to find smallest in an array using pointer
- C Program to merge and sort two arrays
- Un-sortiertes Array and Sortiertes Array
- C Program to Array Deserialization
- C program calculates a given function in range given by user, stores the data in arrays and displays the answer in a table.
- Input reads in the array positions and range for random generation.
Store
- C Program To Store Students Record In A Text File
- C Program To Store Students Record Using Structure
- C program calculates a given function in range given by user, stores the data in arrays and displays the answer in a table.
- C Program to calculate sum of two m*n matrices & store the result in 3 matrix
- C Program to accept n numbers from user store these numbers into an array & calculate average of n numbers
- C Program to accept n numbers & store all prime numbers in an array & display this result
- C program to accept n number from user,store these numbers into an array & count the no of occurrences of each number
- C Program to accept n numbers from user store these numbers into an array & reverse an array elements using function
- C Program to accept 5 names from user & store these names into an array. Sort these array elements in alphabetical order
- C Program to accept n numbers from user,store these numbers into an array & sort the number of an array
- C Program to accept n numbers from user, store these numbers into an array. Find out Maximum & Minimum number from an Array
- C Program to accept data from user store that data into text file
- Accept n number from user, store these number into an array and calculate the average of n number
- C Program - Hash Table to store information about a student
- C Program to Input Student Details into a File For Two Subjects
Two
- Write a c program to find out H.C.F. of two numbers.
- Write a C program to find maximum or equal between two numbers ?
- ADDITION OF TWO MATRICES USING C PROGRAM
- C Program To Find Product Of Two No Using MACRO
- C Program To Swap Two Numbers Without Using Third Variable
- C Program Concatenating Two Strings Into A Third System
- C Program to concatenate two strings without using string functions
- C Program to Interchanging Two Numbers
- C Program produsul scalar a doi vectori .
- C Program The dot product of two vectors
- C Program to two timing functions to measure process time
- C Program to calculate sum of two m*n matrices & store the result in 3 matrix
- C Program to swap the values of two variables by using call by reference
- Menu driven program in C to Calculate Length, Copy into Another Compare Concatenate of Two String
- C Program To Multiply Two Polynomials
- Create Two Singly Linked List Perform Differences Display It C Program
- C Program to Input Student Details into a File For Two Subjects
- Adding two polynomial functions C Program Using Structure
- Program to Add Two Polynomials Using Linked List C Program
- Menu Driven Program to Read Two Integers Find Sum, Difference and Product C Program
- Input Two Numbers and Print Greater Number C Program
Set