Project 1 - Creation of user defined data type to implement the user interfaces for working with ‘Set’ (Mathematical Set theory)
n this project, interfaces for mathematical Set Theory are implemented using C programming language. User can give the input like two list of data and this program will give the output as the union and intersection of these two lists
code
#include<stdio.h>
int i,j;
struct set// structure create
{
int arr_1[20];
int arr_2[20];
int arr_3[20];
};
int main()
{
struct set list;// create object
printf("No of element in the list 1 is :");
scanf("%d",&i);
for (int n=0;n<i;n++)// get the value 1
{
int j=n+1;
printf("\n Enter the %d element :",j);
scanf("%d",&list.arr_1[n]);
}
printf("\nNo of element in the list 2 is :");
scanf("%d",&j);
for (int n=0;n<j;n++)// get the value 2
{
int j=n+1;
printf("\n Enter the %d element :",j);
scanf("%d",&list.arr_2[n]);
}
int array[20];
int f=start(list.arr_1,list.arr_2,&array);
for (int i = 0; i < f; i++)// array converter
{
list.arr_3[i]=array[i];
}
for (int i = 0; i < f; i++)
{
printf("output list %d\n",list.arr_3[i]);// print the output
}
}
int start(int arr1[],int arr2[],int *ptr)
{
int flag=0;
int f=0;
for (int n=0;n<i;n++)// check the first array
{
for(int m=0;m<j;m++)
{
if(check(arr1[n],arr2[m]))// condition checking
{
flag=1;
}
else
{
flag=0;
break;
}
}
if(flag==1)
{
*ptr=arr1[n];// set the value
f++;
ptr++;
}
}
for (int n=0;n<j;n++)// check the second array
{
for(int m=0;m<i;m++)
{
if((check(arr2[n],arr1[m]))==1)// condition checking
{
flag=1;
}
else
{
flag=0;
break;
}
}
if(flag==1)// set the value
{
*ptr=arr2[n];
f++;
ptr++;
}
}
return f;
}
int check(int *num1 ,int *num2)// function defination
{
if(num1==num2)
return 0;
else
return 1;
}