Entropy code in C++

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<math.h>

void main()
{
int c;
float p[5];
float H=0.0;
clrscr();
char str[5];
cout<<"Enter text: ";
cin>>str;
for(int i=0;i<strlen(str);i++)
{
  cout<<"\n Enter probabilty of "<<str[i];
  cin>>p[i];
  H+=(-1)*p[i]*(log(p[i])/log(2.0));
}
cout<<"\n Entropy of the given message : "<<H;
getch();
}

Comments

Popular posts from this blog

Silde show of images In JSP

Compression ratio, Compression factor, saving percentage in C++

Working with database in Vb.net