Hi,
I started learning C and C++ programming languages. I am unable to understand the logic of the given codes... Especially i dont know how "FOR LOOP" works in the given code.
Please explain me in clear manner.
Code:
int main()
{
int H_Matrix[3][6]={{1,1,0,0,1,0},{1,0,0,1,0,1},{1,1,1,0,0,1}};
int i,j,msg_length,sum=0,k;
int message[10][10];
int rows=3,cols=6,r=0,r2,c;
int code[10][10]={0};
int temp[10][10]={0};
printf("enter the message length\n");
scanf("%d",&msg_length);
printf("enter the message in bits maximum 10 bits\n");
for(j=0;j<msg_length;j++)
{
scanf("%d",&message[0][j]);
}
// Please explain me how below code works
for(c=(cols-rows);c<cols;c++,r++)
{
if(H_Matrix[r][c]==0)
{
//swap needed
for(r2=r+1;r2<rows;r2++)
{
if(H_Matrix[r2][c]!=0)
{
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
temp[r][j]=H_Matrix[r][j];
H_Matrix[r][j]=H_Matrix[r2][j];
H_Matrix[r2][j]=temp[r][j];
}
}
}
}
}
//Explain me the logic of given codes
for (r2 = r + 1;r2<rows;r2++)
{
if (H_Matrix[r2][c]== 1)
{
for(j=0;j<cols;j++)
{
H_Matrix[r2][j]=H_Matrix[r2][j]^H_Matrix[r][j];
}
}
}
// Back Substitution//Explain me the logic of given codes
for( r2 = 0;r2<r;r2++)
{
if (H_Matrix[r2][c] == 1)
{
for(j=0;j<cols;j++)
{
H_Matrix[r2][j]=H_Matrix[r2][j]^H_Matrix[r][j];
}
}
}
}