123 Eng

Engineering the engineers™

Home
Source Codes
Engineering Colleges

Training  Reports
Seminar Reports
Placement Papers

Forums

Computer Science / IT
Electronics
Electrical
Mechanical
Chemical
Civil

CAT / MBA

GMAT / Foreign MBA
Latest Jobs

Displaying  Source Code(s)

 Using Shannon's algorithm for code assignment to characters of varying probabilities. -------------------------------------------------------------------------------- Description : This code gives the binary codes to each of the characters having different probabilities of occurence,using the Shannon's algorithm. User must enter the probabilities .Make sure that the sum of all probablities is <= to 1. The character with the highest probability of occurence will be assigned the code of least length, while that of the lowest probability will be assigned the longest length. Before the codes are assigned, the characters are sorted in descending order. Hence, the results displayed also are in descending order. #include #include #include int temp,i,j,col=0,n=100,count=0,b[10][2]; float a[10],sum=100; char c[10][10]; void main() { void part(int,int); clrscr(); printf("Enter number of characters "); while(n>10) { printf("(Not more than 10) "); scanf("%d",&n); } while(sum>1) { printf("Enter their probabilities of occurences
); sum=0; for(i=1;i<=n;i++) { printf("."); scanf("%f",&a[i]); while(a[i]>=1) a[i]=a[i]/10; sum=sum+a[i]; if(sum>1) break; } if(sum>1) printf("Sum of probabilities must be less than or equal to 1 !
); } for(i=0;i<10;i++) { for(j=0;j<10;j++) c[i][j]='*'; } for(i=0;i); part(1,n); printf("The codes are
); for(i=0;i); } getch(); } void part(int low,int high) { int min=100,k,z,sum=0,dif,sum1=0,l=0; z=(high-low); z=abs(z); for(j=0;j<10;j++) for(i=0;i<2;i++) b[j][i]=0; if(z>1) { count++; for(i=low-1;ib[i][0]) { min=b[i][0]; k=b[i][1]; } for(i=low-1;i

Contribute content or training reports / feedback / Comments
job placement papers