Naive pattern matching algorithm


//Naive pattern matching algorithm implementation.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
 int n,m,s;
 clrscr();
 char t[200],p[200],count=0;
 printf("Enter the data for Naive Pattern Match Algorithm
");

 printf("String: ");scanf("%s",t);
 printf("Pattern: ");scanf("%s",p);
 n=strlen(t);
 m=strlen(p);
 printf("Pattern Matched at:");
 for(s=0;s<n-m;s++)
 {
  for(int i=0;i<m;i++)
  {
   if(t[s+i]==p[i]) count++;
  }
  if(count==m)
  printf("%d ",s);
  count=0;
 }
 getch();
}
//program written by Mars.
Read More..

Number Rectangle Pattern

Q. Write a C program to print the following number pattern rectangle as:

1 2 3 4 5 4 5
2 3 4 5 3 4 5
3 4 5 2 3 4 5
4 5 1 2 3 4 5

Ans.

/*c program for number pattern rectangle design*/
#include<stdio.h>
int main()
{

 int n=4,num=5,p=4,r,c,z;
 for(r=1; r<=n; r++,p--)
 {
   for(c=r; c<=num; c++)
      printf(" %d",c);
   for(c=1,z=p; c<=r+1; c++,z++)
     printf(" %d",z);
   printf("
"
);

 }
 getch();
 return 0;
}

/***********************************************************
The output of above program would be:
************************************************************/


Output of Number Rectangle Pattern C program
Figure: Screen-shot for Number Rectangle Pattern C program

Read More..

Blog Archive

Powered by Blogger.