Saturday, 25 November 2017

C Program to check whether an integer array is present in another array

#include<stdio.h>
#include <conio.h>
void main()
{
int a[100],b[100],i,n,m,j,k,flag,flag1=0;
clrscr();
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
scanf("%d",&m);
for(i=0;i<m;i++)
scanf("%d",&b[i]);
for(i=0;i<n;i++)
{
    if(a[i] == b[0] && i+m <= n)
    {
                for(j=i,k=1;k<m;k++,j++)
                {
                         if(a[j] != b[k])
                                 break;
                }
                if(k == m-1)
                {
                                flag1=1;
                                break;
                }
     }
}
if(flag1 ==1)
                printf("Present");
else
                printf("not present");

getch();

No comments:

Post a Comment