Sei sulla pagina 1di 7

CODE:

//Implementation of Vertical redundancy check (VRC)

#include<stdio.h>
#include<conio.h>
void main()
{
int ch,arr[7],i,temp,count;
clrscr();
printf("\t\t\tProgram to do vertical redundancy check");
lable1:
printf("\n\n\n1.Even Parity\n2.Odd Parity\nChoose one option: ");
scanf("%d",&ch);
if(ch==1 || ch==2)
{
printf("Enter a 7 bit dataword: ");
for(i=0;i<7;i++)
{
scanf("%d",&temp);
if(temp==1 || temp==0)
{
arr[i]=temp;
if(temp==1)
{
count++;
}
}
else
{
printf("Invalid input please renter");
i--;
}
}
}
else
{
printf("Invalid choic re-enter");
goto lable1;
}

printf("\n\nBefore parity check code is: ");


for(i=0;i<7;i++)
printf("%d",arr[i]);

if(ch==1)
{
printf("\n\nAfter Even parity check code is: ");
if(count%2==0)
{
arr[7]=0;

}
else
{
arr[7]=1;
}
for(i=0;i<=7;i++)
printf("%d",arr[i]);
}
else
{
printf("\n\nAfter Odd parity check code is: ");
if(count%2!=0)
{
arr[7]=0;
}
else
{
arr[7]=1;
}
for(i=0;i<=7;i++)
printf("%d",arr[i]);
}
getch();
}
OUTPUT:
CODE:

//Implementation of Longitudinal redundancy check (LRC)

#include<stdio.h>
#include<conio.h>
void main()
{
int ch,i,d,j,temp,count=0;
int arr[10][8];
clrscr();
printf("\t\tProgram to do Longitudinal redundancy check");
lable1:
printf("\n\nEnter the number of datawords to be entered: ");
scanf("%d",&d);
printf("\n\n\n1.Even Parity\n2.Odd Parity\nChoose one option: ");
scanf("%d",&ch);
if(ch==1 || ch==2)
{
for(i=0;i<d;i++)
{
printf("Enter a 8 bit dataword: ");
for(j=0;j<8;j++)
{
scanf("%d",&temp);
if(temp==1 || temp==0)
{
arr[i][j]=temp;
}
else
{
printf("Invalid input please renter");
j--;
}
}
}
}
else
{
printf("Invalid choic re-enter");
goto lable1;
}

printf("\n\nBefore parity check codes are:\n");


for(i=0;i<d;i++)
{
for(j=0;j<8;j++)
{
printf("%d",arr[i][j]);
}
printf("\n");
}

if(ch==1)
{
for(j=0;j<8;j++)
{
for(i=0;i<d;i++)
{
if(arr[i][j]==1)
{
count++;
}
}

if(count%2==0)
{
arr[d][j]=0;
count=0;
}
else
{
arr[d][j]=1;
count=0;
}
}
printf("\n\nAfter Even parity check Redunduncy code is: ");
for(j=0;j<8;j++)
{
printf("%d",arr[d][j]);
}
}
else
{
for(j=0;j<8;j++)
{
for(i=0;i<d;i++)
{
if(arr[i][j]==1)
{
count++;
}
}

if(count%2!=0)
{
arr[d][j]=0;
count=0;
}
else
{
arr[d][j]=1;
count=0;
}
}

printf("\n\nAfter Even parity check Redunduncy code is: ");

for(j=0;j<8;j++)
{
printf("%d",arr[d][j]);
}
}

getch();
}
OUTPUT:

Potrebbero piacerti anche