Your Ad Here

Wednesday, January 23, 2008

Entropy Of Given Message

/* C Program to find Entropy Of Given Message */

#include< stdio.h>
#include< conio.h>
#include< math.h>

void main()
{
int c,i;
float p,sum=0,it;
clrscr();
printf("**** INFORMATION CONTENT OF FIVE MESSEGES *****\n\n");
printf("Enter No Of Messages : ");
scanf("%d",&c);
printf("\n");
for(i=1;i< =c;i++)
{
printf("\tEnter The %d Probability\t: ",i);
scanf("%f",&p);
it = p* (log(1/p)) / log(2);
sum=sum+it;
}
printf("\nEntropy Of The Given Message : %f",sum);
getch();
}
/******************** OUTPUT *************************

**** INFORMATION CONTENT OF FIVE MESSEGES *****

Enter No Of Messages : 5

Enter The 1 Probability : 0.1
Enter The 2 Probability : 0.2
Enter The 3 Probability : 0.3
Enter The 4 Probability : 0.36
Enter The 5 Probability : 0.04

Entropy Of The Given Message : 2.034038 */

3 comments:

Anonymous said...

It is remarkable, rather valuable message

Anonymous said...

I consider, that you are mistaken. Let's discuss it. Write to me in PM.

Anonymous said...

CORRECT CODE:

#include
#include
#include

int main()
{
int c,i;
float *p,H,sum=0;
void clrscr();
printf("**** INFORMATION CONTENT OF FIVE MESSEGES *****\n\n");
printf("Enter No Of Messages : ");
scanf("%d",&c);
printf("\n");
for(i=1;i<=c;i++)
{
printf("\tEnter The %d Probability\t: ",i);
scanf("%f",&p);
H+=(-1)*p[i]*(log10(p[i])/log10(2.0));
sum=sum+H;
}
printf("\nEntropy Of The Given Message : %f",H);
getch();
}

Your Ad Here