Input five numbers in two different arrays and print common elements of these arrays.
#include <stdio.h>
#include <conio.h>
void main ( )
{
int n[5], n1[5], n2[5], a, b, c = 0;
clrscr ( );
for ( a = 0; a < 5; a++ )
{
printf ("\n\t\t Enter a number in 1st array......:"); scanf ("%d", & n[a]);
}
for ( a = 0; a < 5; a++ )
{
printf ("\n\t\t Enter a number in 2nd array......:"); scanf ("%d", & n1[a]);
}
for ( a = 0; a < 5; a++ )
{
for ( b = 0; b < 5; b++ )
{
if ( n[a] == n1[b] )
{
n2[c++] = n[a];
}
}
}
printf ("\n\n\t\t Common elements are\n\n\t\t");
for ( a = 0; a < c; a++ )
printf (" %d", n2[a]);
getch ( );
}
Click here to contact us
No comments:
Post a Comment