Friday, November 23, 2012

IN A GIVEN STRING, FIND THE FREQUENCY OF OCCURRENCE OF A PARTICULAR LIST


/*  IN A GIVEN STRING, FIND THE FREQUENCY OF OCCURRENCE OF  A PARTICULAR LIST
*/

#include<stdio.h>
#include<conio.h>
#include<string.h>
#define MAX 30

void main()
{
            char str[MAX],str1[MAX];
            int i,j,len1,len2,flag,freq;
            clrscr();
            printf(" \n Enter a String : ");
            gets(str);
            printf("\n Enter a List : ");
            gets(str1);
            len1=strlen(str);
            len2=strlen(str1);
            freq=0;
            for(i=0;i<len1;)
            {
                        flag=0;
                        for(j=0;j<len2;)
                        {
                                    if(str[i]==str1[j])
                                    {
                                                flag++;
                                                i++,j++;
                                    }
                                    else
                                    {
                                                i++;
                                                break;
                                    }

                        }
                        if(flag==len2)
                                    freq++;
            }
            printf("\n The Frequency of occurence of \n\t\"%s\" in \"%s\" is %d",str1,str,freq);
            getch();
}

/*
            =====OUT PUT=====

      1. Enter a String : KAUNDINYA

             Enter a List : KAUN

             The Frequency of occurence of
                    "KAUN" in "KAUNDINYA" is 1
           
      2. Enter a String : bharath

             Enter a List : kaun

             The Frequency of occurence of
            "kaun" in "bharath" is 0

*/

0 comments:

Post a Comment