Program:
#include<iostream.h>
#include<conio.h>
void main()
{
char a[80],ch;
int I,j,count,occured,total=0;
clrscr();
cout<<"\nEnter the stream of characters terminated by \ "Enter\ " key: \n\n";
ch=getche();
while(ch!='\r');
{
a[total++]=ch;
ch=getche();
}
cout<<"\n\nInputted Stream of Characters is: \n\n";
for(I=0;I<total;I++)
cout<<a[I];
cout<<"\n\n**********OUTPUT**********\n";
cout<<"\nTotal characters inputted: "<<I<<"\n";
cout<<"\nCharacter Frequency\n\n";
for(I=0;I<total;I++)
{
occured=0;
count=1;
for(j=I-1;j>=0;j--)
{
if(a[j]==a[I])
{
occured=1;
break;
}
}
if(!occured)
{
for(j=I+1;j<total;j++)
{
if(a[j]==a[I])
count++;
}
cout<<" "<<a[I]<<" "<<count<<"\n";
}
}
getch();
}