15. Given are two linear arrays of integers, one containing 20 elements and the
other containing 15 elements. After reading data to obtain values for all items
in each array, print the values of only those integers that appear in both the
arrays.
#include
#include
void main()
{
int a[20],b[15],i,j;
clrscr();
for(i=0;i<20;i++)
{
printf("\nEnter the value%d of array1:",i+1);
scanf("%d",&a[i]);
}
for(i=0;i<15;i++)
{
printf("\nEnter the value%d of array2:",i+1);
scanf("%d",&b[i]);
}
for(i=0;i<20;i++)
{
for(j=0;j<15;j++)
{
if(a[i]==b[j])
{
printf("\n%d",a[i]);
}
}
}
getch();
}
/*Output
Enter the value13 of array1:13
Enter the value14 of array1:14
Enter the value15 of array1:15
Enter the value16 of array1:16
Enter the value17 of array1:17
Enter the value18 of array1:18
Enter the value19 of array1:19
Enter the value20 of array1:20
Enter the value1 of array2:21
Enter the value2 of array2:22
Enter the value3 of array2:23
Enter the value4 of array2:25
Enter the value5 of array2:26
Enter the value6 of array2:27
Enter the value7 of array2:28
Enter the value8 of array2:29
Enter the value9 of array2:1
Enter the value10 of array2:2
Enter the value11 of array2:3
Enter the value12 of array2:45
Enter the value13 of array2:46
Enter the value14 of array2:48
Enter the value15 of array2:69
1
2
3
*/
other containing 15 elements. After reading data to obtain values for all items
in each array, print the values of only those integers that appear in both the
arrays.
#include
#include
void main()
{
int a[20],b[15],i,j;
clrscr();
for(i=0;i<20;i++)
{
printf("\nEnter the value%d of array1:",i+1);
scanf("%d",&a[i]);
}
for(i=0;i<15;i++)
{
printf("\nEnter the value%d of array2:",i+1);
scanf("%d",&b[i]);
}
for(i=0;i<20;i++)
{
for(j=0;j<15;j++)
{
if(a[i]==b[j])
{
printf("\n%d",a[i]);
}
}
}
getch();
}
/*Output
Enter the value13 of array1:13
Enter the value14 of array1:14
Enter the value15 of array1:15
Enter the value16 of array1:16
Enter the value17 of array1:17
Enter the value18 of array1:18
Enter the value19 of array1:19
Enter the value20 of array1:20
Enter the value1 of array2:21
Enter the value2 of array2:22
Enter the value3 of array2:23
Enter the value4 of array2:25
Enter the value5 of array2:26
Enter the value6 of array2:27
Enter the value7 of array2:28
Enter the value8 of array2:29
Enter the value9 of array2:1
Enter the value10 of array2:2
Enter the value11 of array2:3
Enter the value12 of array2:45
Enter the value13 of array2:46
Enter the value14 of array2:48
Enter the value15 of array2:69
1
2
3
*/