#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int i,j,k,n,m,flag=0;
char t[40],p[30];
clrscr();
printf("Enter text: ");
gets(t);
printf("\nEnter pattern: ");
gets(p);
n=strlen(t);
m=strlen(p);
for(i=0;i<=n-m;i++)
{
j=0;
while(j<m && p[j]==t[j+i])
{
j++;
if(j==m)
{
flag=1;
k=i+1;
}
else
flag=0;
}
}
if(flag==1)
printf("\nPattern found at position: %d\n ",k);
else
printf("\nPattern not found in text \n");
getch();
}
#include<conio.h>
#include<stdlib.h>
void main()
{
int i,j,k,n,m,flag=0;
char t[40],p[30];
clrscr();
printf("Enter text: ");
gets(t);
printf("\nEnter pattern: ");
gets(p);
n=strlen(t);
m=strlen(p);
for(i=0;i<=n-m;i++)
{
j=0;
while(j<m && p[j]==t[j+i])
{
j++;
if(j==m)
{
flag=1;
k=i+1;
}
else
flag=0;
}
}
if(flag==1)
printf("\nPattern found at position: %d\n ",k);
else
printf("\nPattern not found in text \n");
getch();
}
Output:
No comments:
ReplyDeletePost a CommentNo comments:
Post a CommentNo comments:
Post a CommentNo comments:
Post a CommentNo comments:
Post a CommentNo comments:
Post a CommentNo comments:
Post a CommentNo comments:
Post a CommentNo comments:
Post a CommentNo comments:
Post a CommentNo comments:
Post a CommentNo comments:
Post a CommentNo comments:
Post a CommentNo comments:
Post a CommentNo comments:
awesome
ReplyDeleteThanks for the program
ReplyDelete