#include<stdio.h>
#include<conio.h>
int main()
{
int A[5],B[5],C[10];
int i,k,j;
int flag;
clrscr();
printf("enter 5 elements of A");
for(i=0;i<5;i++)
{
scanf("%d",&A[i]);
}
printf("\nenter elements of B");
for(j=0;j<5;j++)
{
scanf("%d",&B[j]);
}
k=0;
for(i=0 ;i<5;i++)
{
C[k]=A[i];
k++;
}
for(j=0;j<5;j++)
{
flag=0;
for(i=0;i<5;i++)
{
if(B[j]==A[i])
{
flag=1;
break;
}
}
if(flag==0)
{
C[k]=B[j];
k++;
}
}
for(i=0;i<k;i++)
printf("a union b is %d\n",C[k]);
return 0;
}
union of two sets
Page 1 of 110 Replies - 195 Views - Last Post: 07 July 2012 - 08:55 AM
#1
union of two sets
Posted 06 July 2012 - 11:47 PM
Replies To: union of two sets
#3
Re: union of two sets
Posted 06 July 2012 - 11:56 PM
suyed, on 06 July 2012 - 11:47 PM, said:
i cant get a correct output for dis code.. i m getin some garbage values..
please help me out..
#include<stdio.h>
#include<conio.h>
int main()
{
int A[5],B[5],C[10];
int i,k,j;
int flag;
clrscr();
printf("enter 5 elements of A");
for(i=0;i<5;i++)
{
scanf("%d",&A[i]);
}
printf("\nenter elements of B");
for(j=0;j<5;j++)
{
scanf("%d",&B[j]);
}
k=0;
for(i=0 ;i<5;i++)
{
C[k]=A[i];
k++;
}
for(j=0;j<5;j++)
{
flag=0;
for(i=0;i<5;i++)
{
if(B[j]==A[i])
{
flag=1;
break;
}
}
if(flag==0)
{
C[k]=B[j];
k++;
}
}
for(i=0;i<k;i++)
printf("a union b is %d\n",C[k]);
return 0;
}
Skydiver, on 06 July 2012 - 11:48 PM, said:
output
Skydiver, on 06 July 2012 - 11:48 PM, said:
sorry i m using dis web for the first so getting difficult to use it bt i will learn it slowly...
#4
Re: union of two sets
Posted 07 July 2012 - 12:00 AM
This post has been edited by Skydiver: 07 July 2012 - 12:01 AM
#5
Re: union of two sets
Posted 07 July 2012 - 12:17 AM
i just did on a trial and error basis i actually didnot understand what actualy has been happening over that last for loop ..
can u explain me
This post has been edited by jimblumberg: 07 July 2012 - 05:28 AM
Reason for edit:: Removed unecessary quote tags
#6
Re: union of two sets
Posted 07 July 2012 - 12:23 AM
Now, go back and look at your lines 44-45. How is this similar or different to lines 11-14, 16-19?
#7
Re: union of two sets
Posted 07 July 2012 - 12:43 AM
i then increaments its value by 1 and checks the condition whether it is less than 5, if it holds true, it agains goes inside the loop and performs the statements till 1<5 ie 1=4.
when i=5 it does nt go inside the loop instead it performs the next statement after the for loop.
This post has been edited by jimblumberg: 07 July 2012 - 05:29 AM
Reason for edit:: Removed unecessary quote tags
#8
Re: union of two sets
Posted 07 July 2012 - 12:47 AM
#9
Re: union of two sets
Posted 07 July 2012 - 08:40 AM
aresh, on 07 July 2012 - 01:17 PM, said:
u must be master in c but i m not and so i hav joined dis ..
dis i my first day and a very first topic so pls,,,
if u dont wanna clr my doubts its fine bt dont try to act oversmart wid me..
#10
Re: union of two sets
Posted 07 July 2012 - 08:45 AM
#11
Re: union of two sets
Posted 07 July 2012 - 08:55 AM
suyed, on 07 July 2012 - 10:40 AM, said:
u must be master in c but i m not and so i hav joined dis ..
dis i my first day and a very first topic so pls,,,
if u dont wanna clr my doubts its fine bt dont try to act oversmart wid me..
Since the OP doesn't seem to want to behave I'm going to close this topic.
Jim
|
|

New Topic/Question
This topic is locked




MultiQuote




|