Data Communication network programs (DCN)
Data Communication network(DCN) Program to implement LRC method (Single-Parity Check)
Write a program to implement LRC method (Single-Parity Check)
#include<stdio.h>
#include<conio.h>
void main()
{
int l1,bit[100],count=0,i,choice;
clrscr();
printf("Enter the length of data stream: ");
scanf("%d",&l1);
printf("\nEnter the data stream ");
for(i=0;i<l1;i++)
{
scanf("%d",&bit[i]);
if(bit[i]==1)
count=count+1;
}
printf("Number of 1's are %d",count);
printf("\nEnter the choice to implement parity bit");
printf("\n1-Sender side\n2-Receiver side\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
if(count%2==0)
bit[l1]=0;
else
bit[l1]=1;
printf("\nThe data stream after adding parity bit is\n");
for(i=0;i<=l1;i++)
printf("%d",bit[i]);
break;
case 2:
if(count%2==0)
printf("There is no error in the received data stream");
else
printf("There is error in the received data stream");
break;
default:
printf("Invalid choice");
break;
}
getch();
}
OUTPUT
Enter the length of data stream: 10
Enter the data stream 1 1 0 1 0 1 1 1 0 1
Number of 1's are 7
Enter the choice to implement parity bit
1-Sender side
2-Receiver side
1
The data stream after adding parity bit is
11010111011
Enter the length of data stream: 10
Enter the data stream 1 1 1 1 1 0 0 0 1 0
Number of 1's are 6
Enter the choice to implement parity bit
1-Sender side
2-Receiver side
2
There is no error in the received data stream