CN Practical
CN Practical
CN Practical
getchar();
return 0;
}
OUTPUT:
Parity of no 3 = even
getchar();
return 0;
}
OUTPUT:
Parity of no 7 = odd
/*
* C program to implement Checksum
*/
#include<stdio.h>
#include<math.h>
int sender(int arr[10],int
n)
{ int checksum,sum=0,i;
printf("\n****SENDER SIDE****\n");
for(i=0;i<n;i++) sum+=arr[i];
printf("SUM IS: %d",sum); checksum=~sum;
//1's complement of sum
printf("\nCHECKSUM IS:%d",checksum);
return checksum;
} void receiver(int arr[10],int n,int
sch)
{
int checksum,sum=0,i;
printf("\n\n****RECEIVER SIDE****\n");
for(i=0;i<n;i++) sum+=arr[i];
printf("SUM IS:%d",sum); sum=sum+sch;
checksum=~sum; //1's complement of sum
printf("\nCHECKSUM IS:%d",checksum);
} void main() { int n,sch,rch; printf("\nENTER SIZE OF THE
STRING:"); scanf("%d",&n); int arr[n]; printf("ENTER THE
ELEMENTS OF THE ARRAY TO CALCULATE CHECKSUM:\n"); for(int
i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
sch=sender(arr,n);
receiver(arr,n,sch);
}
OUTPUT:
1011
0111
****SENDER SIDE****
****RECEIVER SIDE****
SUM IS:1122
CHECKSUM IS:0
#include<stdio.h>
#include <math.h>
#include <stdio.h>
// If current boit is 1
if (code[j] == 1)
count++;
}
// Update i i
= i + 2 * position;
} if (count %
2 == 0) return
0; else
return 1;
}
int N = 4;
// Function Call
solve(input, N);
}
OUTPUT:
#include<stdio.h>
char data[20],div[20],temp[4],total[100];
int i,j,datalen,divlen,len,flag=1; void
check(); int main() { printf("Enter the
total bit of data:");
scanf("%d",&datalen);
printf("\nEnter the total bit of divisor");
scanf("%d",&divlen); len=datalen+divlen-1;
printf("\nEnter the data:");
scanf("%s",&data);
printf("\nEnter the divisor");
scanf("%s",div);
for(i=0;i<datalen;i++)
{
total[i]=data[i];
temp[i]=data[i];
} for(i=datalen;i<len;i++) //padded with zeroes
corresponding to divlen total[i]='0'; check();
// check for crc for(i=0;i<divlen;i++) // append crc
output (remainder) at end of temp temp[i+datalen]=data[i];
printf("\ntransmitted Code Word:%s",temp); printf("\n\nEnter the
received code word:"); scanf("%s",total); check();
for(i=0;i<divlen-1;i++) if(data[i]=='1')
{ flag=0; break;
} if(flag==1) printf("\nsuccessful!!");
else printf("\nreceived code word contains
errors...\n");
}
void check()
{
for(j=0;j<divlen;j++)
data[j]=total[j];
while(j<=len)
{ if(data[0]=='1') // in XOR ans remains as it is
except in case of 1 for(i = 1;i <divlen ; i++)
data[i] = (( data[i] == div[i])?'0':'1'); for(i=0;i<divlen-1;i++)
// left shift data word by 1 after div data[i]=data[i+1];
data[i]=total[j++]; // replace empty right by total
}
}
OUTPUT:
OUTPUT:
enter window size
#include<stdio.h>
int main() { int
w,i,f,frames[50];
printf("Enter window size:
"); scanf("%d",&w);
printf("\nEnter number of frames to transmit:
"); scanf("%d",&f);
printf("\nEnter %d frames:
",f);
for(i=1;i<=f;i++)
scanf("%d",&frames[i]);
printf("\nWith sliding window protocol the frames will be sent in
the following manner (assuming no corruption of frames)\n\n");
printf("After sending %d frames at each stage sender waits for
acknowledgement sent by the receiver\n\n",w);
for(i=1;i<=f;i++)
{
if(i%w==0)
{
printf("%d\n",frames[i]);
printf("Acknowledgement of above frames sent is received by
sender\n\n"); } else
printf("%d ",frames[i]);
}
if(f%w!=0)
printf("\nAcknowledgement of above frames sent is received by
sender\n");
return 0;
}
OUTPUT:
Enter 5 frames: 12 5 49 4 6
With sliding window protocol the frames will be sent in the following manner (assuming no
corruption of frames)
After sending 3 frames at each stage sender waits for acknowledgement sent by the receiver
12 5 49
46
OUTPUT:
0 3 5 99
3 0 99 1
5402
99 1 2 0
Distance4
Distance1
Distance2