#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{ int i,n,r;
float I[10],p[10],H[10],s,TI,TH,IR;
clrscr();
printf(“\n\n Enter the total number of symbols:”);
scanf(“%d”,&n);
xx:printf(“\n\n Enter the probablities:-\n”);
for(i=0;i<n;i++)
scanf(“%f”,&p[i]);
for(i=0,s=0;i<n;i++)
s+=p[i];
printf(“\n\n Sum is %f”,s);
if(s==1)
{
for(i=0,TI=0;i<n;i++)
{I[i]=log(1/p[i])/log(2);
printf(“\n\nI[%d]=%f”,i,I[i]);
T I+=I[i];
}
for(i=0,TH=0;i<n;i++)
{
H[i]=p[i]*(log(1/p[i])/log(2));
printf(“\n\nH[%d]=%f”,i,H[i]);
TH+=H[i];
}
printf(“\n\n Enter the rate r:”);
scanf(“%d”,&r);
IR=r*TH;
printf(“\n\nInformation rate is %f”,IR);
}
else
{
printf(“\n\nEntered probablities are not correct please re-enter”);
goto xx;
}
getch();}}
Output:-
Enter the total number of symbols:3
Enter the probablities:- .3 .3 .4
Sum is 1.000000
I[0]=l.736966 Bits
I[1]=1.736966 Bits
I[2]=1.321928 Bits
H[0]=0.521090 Bits/Message
H[1]=0.521090 Bits/Message
H[2]=0.528771 Bits/Message
Enter the rate r:1000
Information rate is 1570.950562 Bits/Seconds.
No comments:
Post a Comment