Skip to main content

Intersection of Two Sets

// Intersection of Two Sets

#include<stdio.h>
#define SIZE 10
int main()
{
    int a[SIZE],b[SIZE],i,j,m,n;
    printf("Enter the Number of Elements in A : ");
    scanf("%d",&m);
    printf("Enter the Number of Elements in B : ");
    scanf("%d",&n);

    printf("\nSET-A\n");
    for(i=0;i<m;i++)
    {
        printf("Enter the Elements a[%d] : ",i);
        scanf("%d",&a[i]);
    }
    printf("\nSET- B\n");
    for(j=0;j<n;j++)
    {
        printf("Enter the Elements b[%d] : ",j);
        scanf("%d",&b[j]);
    }

    printf("\nA intersection B : {");

    for(i=0;i<m;i++)
    {
        for(j=0;j<n;j++)
        {
            if(a[i]==b[j])
            {
                printf(" %d",a[i]);
                break;
            }
        }
    }
    printf(" }\n");
    return 0;
}


Comments

Popular posts from this blog

Simple Matrix

// Simple Matrix Upto n Numbers. (Dynamic) #include<stdio.h> int main() {     int i,j,k=1,rc;     printf("Enter the No of Columns : ");     scanf("%d",&rc);     for(i=0;i<rc;i++)     {          printf("|");         for(j=0;j<rc;j++,k++)         {             printf("%3d",k);         }         printf(" | \n");     }     return 0; }

Lower Triangular Matrix

// Lower Triangular Matrix #include<stdio.h> int main() {     int i,j,k,m,s=1,rc;     printf("Enter the No of Raws and Columns : ");     scanf("%d",&rc);       for(i=1;i<rc;i++)     {         for(m=0;m<i;m++) // for loop which prints numbers.         {             printf("%3d",s);             s++;         }         for(j=rc;j>i;j--) // for loop which prints 0.         {             printf("  0");         }         printf("\n");     }     return 0; }

Transpose of Matrix

// Transpose of Matrix #include<stdio.h> #define SIZE 5 int main() {     int a[SIZE][SIZE],transpose[SIZE][SIZE];     int i,j,r,c;     printf("Enter Rows of Matrix : ");     scanf("%d",&r);     printf("Enter Rows of Matrix : ");     scanf("%d",&c);         for(i=0;i<r;i++)     {         for(j=0;j<c;j++)         {             printf("Enter Elements [%d][%d] : ",i,j);             scanf("%d",&a[i][j]);         }     }     for(i=0;i<r;i++)     {         for(j=0;j<c;j++)         {             transpose[j][i] = a[i][j];         }     }     printf("Matrix \n");     for(i=0;i...