C Program to create two sets and then find intersection between these two sets. || Discrete Mathematics

// Program to find Intersection Between two sets.

#include <stdio.h>
int main() {
    int n1,n2;
    printf("Enter your number of Element in Set 1\n");
    scanf("%d",&n1);
    int a[n1];
    printf("Enter Your Elements in Set 1\n");
    for(int i=0;i<n1;i++)
    scanf("%d",&a[i]);
    printf("Enter Your number of element in Set 2\n");
    scanf("%d",&n2);
    int b[n2],c[1000];
    printf("Enter Your element in set 2\n");
    for(int i=0;i<n2;i++)
    scanf("%d",&b[i]);
    int k=0;
    for(int i=0;i<n1;i++)
    {
        for(int j=0;j<n2;j++)
        {
            if(a[i]==b[j])
            {
            c[k]=a[i];
            k++;
            }
        }
    }
    printf("Intersection of These two sets is: ");
    for(int i=0;i<k;i++)
    printf("%d ",c[i]);

    return 0;
}

No comments:

Post a Comment

Operator Overloading in C++

#include<iostream> using namespace std; class Complex { private: int real, imag; public: Complex(int r = 0, int i = 0){       re...