Monday, 28 April 2014

ARITHMATIC ENCODING

 #include<stdio.h>
#include<conio.h>
int main()
{
int i,j,n,x,index,sl[20],temp3;
float array[20],code,temp,arrayreference[20],sum=0,code1;
char words[20],temp1,wordsreference[20];
printf("enter size of words\n");
scanf("%d",&n);
x=0;
printf("enter of words\n");
for(i=0;i<n;i++)
{
scanf("%s",&words[i]);
wordsreference[i]=words[i];
}
printf("enter the word codes\n");
for(i=0;i<n;i++)
{
scanf("%f",&array[i]);
sl[i]=i;
sum=sum+array[i];
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(array[i]<array[j])
{
temp=array[i];
array[i]= array[j];
array[j]=temp;
temp1= words[i];
words[i]=words[j];
words[j]=temp1;
temp3=sl[i];
sl[i]=sl[j];
sl[j]=temp3;
}
}
}
for(i=0;i<n;i++)
{
printf("%c\t %f\n",words[i],array[i]);
}
arrayreference[0]=0;
for(j=0;j<n;j++)
{
arrayreference[j+1]=arrayreference[j]+array[j];
}
for(j=0;j<=n;j++)
{
array[j]=arrayreference[j];
}
while(x!=n)
{
for(i=0;i<n;i++)
{
if(x==sl[i])
{
index= i;
}
}
arrayreference[0]=arrayreference[index];
arrayreference[n]=arrayreference[index+1];
code=arrayreference[n]-arrayreference[0];
code=code/(10*sum);
for(i=1;i<n;i++)
{
code1=code*array[i]*10;
arrayreference[i]=arrayreference[0]+code1;
}
x++;
for(j=0;j<=n;j++)
{
printf("%f\t",arrayreference[j]);
}
printf("\n\n");
}
printf("\n\n\n given text is compressed to single codeword \n in the range : %f < codeword < %f",arrayreference[0],arrayreference[n]);
getch();

}

No comments:
Write comments

Featured post

List of Universities in Karnataka offering M.Sc Computer Science

The post-graduate programme in Computer Science (M.Sc Computer Science) contains two academic years duration and having a four semesters....

Popular Posts

Copyright @ 2011-2016