#include<stdio.h>
#include<conio.h>
#include<math.h>>
main()
{
int k,i,r,n,j,a[100],m,p,b[100],count=0,count1=0,q,w,g,h,l,z,x,x1;
printf("enter the length of the data word:");
scanf("%d",&k);
printf("\nenter the data word:");
for(i=1;i<=k;i++)
{
scanf("%d",&a[i]);
}
r=1;
while((k+r+1)>pow(2,r))
r++;
printf("\n r=%d",r);
n=k+r;
j=1;
m=0;
for(i=1; i<=n; i++)
{
p=pow(2,m);
if(i==p)
{
b[i]=0;
m++;
}
else
{
b[i]=a[j];
j++;
}
}
printf("\n INTERMEDIATE CODE WORD IS \n");
for(i=1; i<=n; i++)
printf("%d",b[i]);
count=0;
i=1;
// for b[1]
for(z=2i-1;z<=n;z++)
{
printf("%d %d \n",z,b[z]);
if(b[z]==1)
{
count++;
}
i++;
}
if(count%2==0)
b[1]=0;
else
b[1]=1;
// b[g]; g=2,4,8,....
i=1;
for(q=1;q<=n;q++)
{
i=1;
count1=0;
g=pow(2,q);
h=pow(2,(q-1));
printf("%d %d",g,h);
for(x=h*((4*i)-2);x<=n;x++)
{
printf("%d %d",i,x);
x1=x;
for(l=x;l<x1+g;l++)
{
printf("%d %d",l,x);
if(b[x]==1)
count1++;
x++;
}
i++;
printf("%d %d",i,x);
}
if(count1%2==0)
b[g]=0;
else
b[g]=1;
}
printf("\nhamming code: ");
for(i=1; i<=n; i++)
printf("%d",b[i]);
}
lalitha2294
0
Newbie Poster
Recommended Answers
Jump to PostWhat error?
Jump to PostYour usage of one-letter variable names, which are all declared at the very top of your
main()
function, has your program nearly impossible to read, let alone debug. You need to provide descriptive variable names if you want your stuff to be self explanatory. Do you seriously think it's good …
All 5 Replies
deceptikon
1,790
Code Sniper
Team Colleague
Featured Poster
Begginnerdev
commented:
Why is this voted down? He provided no error in op.
+9
lalitha2294
0
Newbie Poster
lalitha2294
0
Newbie Poster
Tumlee
42
Junior Poster in Training
lalitha2294
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.