# Need C programme for Set operations



## techking_dinesh (Jul 18, 2010)

Hello.
I need a little help with c.

I have to code a programme with following features.
Enter 2 Sets and display them on Screen in sorted order with no elements repeated ( Using array )
Then Using Switch case to perform the following operations
1. Union
2. Intersection
3. difference
4. Symmetric Difference

i tried google and got some codes but those are of high level for me

plz help

I hav managed d most basic part of d code as follows:


```
#include<stdio.h>
#include<conio.h>
void main()
{
int a[50],b[50],c[50],size1,size2,i=0,j=0,z;
clrscr();
printf("\n Set Operations Menu");
printf("\n 1. Union of Set");
printf("\n 2. Intersection of Set");
printf("\n 3. Difference of Set");
printf("\n 4. Symmetric Difference of Set");
printf("\n 5. Exit\n\n\n");
// switch(z)
printf("\n Enter the Size of Set A: ");
scanf("%d",&size1);
printf("\n Enter %d elements for set A: ",size1);
for(i=0;i<size1;i++)
    {
    scanf("%d",&a[i]);
    }
printf("\n Enter the Size of Set B: ");
scanf("%d",&size2);
printf("\n Enter %d elements for set B: ",size2);
for(j=0;j<size2;j++)
    {
    scanf("%d",&b[j]);
    }
printf("\n A is ");
printf("A={");
for(i=0;i<size1;i++)
{
printf("%d,",a[i]);
}
printf("\b}");
printf("\n B is ");
printf("B={");
for(j=0;j<size2;j++)
{
printf("%d,",b[j]);
}
printf("\b}");
getch();
}
```

Waiting for solution


----------



## arpanmukherjee1 (Jul 18, 2010)

techking_dinesh said:


> Hello.
> I need a little help with c.
> 
> I have to code a programme with following features.
> ...



1. merging two array
2. sorting the array Bubble Search
3. UNION step 1,2
4. INTERSECTION take 1st ele of arr1 and try to find it in arr2. repete for all elements of arr1. if found place in arr3. sort arr3.
5. DIFF - apply step 4. logic with a slight twist
6. dont know what "Symmetric Difference" is


----------



## Sukhdeep Singh (Jul 18, 2010)

Here is zip of programs i made long long time back doing the same thing i guess

Set.zip


----------



## techking_dinesh (Jul 21, 2010)

@ARPAN:
Thanks for d algorithm. I needed the syntax. I was clear in algorithm

@Sukhdeep
Thanks a lot bro.. Totally satisfied with your help.. I will manage the symmetric difference on your syntax

And it would be great if you could share all your c programme with me. It will really help me a lot.


----------



## Sukhdeep Singh (Jul 21, 2010)

Thanks a lot man...Cant share all programs..source code will get leaked lol

No just joking...actually they are quite messed up. I remember this because we were asked to make this in 4 differnt langugaes at college time and i had it in mail since we used to get this print out early morning in college campus 

LOL, those where the days man


----------



## techking_dinesh (Jul 25, 2010)

Alrite.. No probs..

But ma college professor keeps changing the programme question

now he wants the programme to be done using functions and he wants the create set and display set option in the menu itself..... (

M Trying it out day and night ... damn


----------



## arpanmukherjee1 (Jul 25, 2010)

r u new to programming ???

those things r real easy ....as a matter of fact u should be using functions to make ur code _modular_, regardless of the prg lang.

set display should also be seperate function.

post ur prg. , as far as u have attempted solving the question.

the real thing is the algorithm design and the data structures. if u dont get it try solving this (question of this months Linux For You  <Code Chef>).

Q. How many ways r there to arrange the basic mathematical operation {+,-,*,/} in the expression 7~7~7~7~7 (~ = one operation) so that the result is 55.

NOTE: i posted a part of the question in here only, find it, i myself answered the question. bit like CRACK THE CODE


----------



## techking_dinesh (Jul 29, 2010)

I ll post my programme here soon..


----------

