Home » Sometech » WAP to calculate frequency of a particular character in a stream of data.

WAP to calculate frequency of a particular character in a stream of data.

#include <stdio.h>

#define S 41

void main()

{

 char a[S],ch1,ch2;

int i,total=0,occr=0;

printf(“\nEnter the string of length <= %d \n”,S-1);

ch1=getche();

while(ch1!=’\r’)

{

 a[total++]=ch1;

ch1=getche();

}

printf(“\nEnter the character to be checked :”);

scanf(“%c”,&ch2);

printf(“\nInputted stream of characters is: \n”);

for(i=0;i<total;i++)

{

   printf(“%c”,a[i]);

    if(a[i]==ch2)

      occr++;

}

printf(“\nCharacter %c has occured %d times “,ch2,occr);

getch();

}

Advertisements

SoME Tech

Error: Twitter did not respond. Please wait a few minutes and refresh this page.

%d bloggers like this: