You are on page 1of 7

2.

Write a program to compute CRC code for the polynomials CRC-12, CRC-16 and CRC CCIP

#include<stdio.h>

#include<conio.h>

void main()

int f[150],g[150],r[150],t[150],i,j,k,m,n,c=0;

clrscr();

printf("\n Enter f: ");

scanf("%d",&n);

for(i=0;i<n;i++)

scanf("%d",&f[i]);

t[i]=f[i];

printf("\n Enter g: ");

scanf("%d",&m);

for(i=0;i<m;i++)

scanf("%d",&g[i]); }

for(i=n;i<n+m;i++)

t[i]=0;

for(i=0;i<n;i++)

k=i;

if(t[i]==1)

for(j=0;j<m;j++,k++)

if(t[k]==g[j])

t[k]=0;

else
t[k]=1;

printf("\n check sum is : ");

for(i=n;i<m+n-1;i++)

printf(" %d ",t[i]);

f[i]=t[i];

printf("\n\n BCS : ");

for(i=0;i<m+n-1;i++)

printf(" %d ",f[i]);

printf("\n\nEnter received data : ");

for(i=0;i<m+n-1;i++)

scanf("%d",&r[i]);

for(i=0;i<n;i++)

k=i;

if(r[i]==1)

for(j=0;j<m;j++,k++)

if(r[k]==g[j])

r[k]=0;

else

r[k]=1;

printf("Received data checksum\n");


for(i=n;i<m+n-1;i++)

printf("%d",r[i]);

if(r[i]!=0)

c=1;

if(c==1)

printf("\n Error ");

else

printf("\n NO error");

getch();

OUTPUT :

Enter f: 24

111100001010101010000000

Enter g: 12

110000001111

check s u m i s : 0 1 0 0 0 0 0 0 1 1 0

BCS:1 1 1 1 0 0 0 0 1 0 1 0 1 0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0

Enter received data:

1 1 1 1 0 0 0 0 1 0 1 0 1 0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 10

Received data check sum is

00000000000

NO error
3. Develop a simple data link layer that performs the flow control using the sliding window
protocol and loss recovery using the Go-Back-N mechanism

#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("\n Acknowledgement of above frames sent is received by sender\n");
return 0;

Output
Enter window size: 3
Enter number of frames to transmit: 5
Enter 5 frames: 12 5 89 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 89
Acknowledgement of above frames sent is received by sender
46
Acknowledgement of above frames sent is received by sender
// 4. Implement Dijsktra’s algorithm to compute the shortest path through a network

#include<stdio.h>
#include<conio.h>
#define INFINITY 10000
void main()
{
int gptr[20][20],set[20],path[20],length[20],s,i,j,k,n,m,temp,c;
clrscr();
/* INPUT */
printf("Enter No Of Vertexes\n");
scanf("%d",&n);
printf("Enter Adjacency Matrix of a Graph \n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
scanf("%d",&gptr[i][j]);
}
printf("Enter Source node \n");
scanf("%d",&s);

/* INTIALIZATION PART */

for(i=1;i<=n;i++)
set[i]=0;
for(i=1;i<=n;i++)
{
if(gptr[s][i]==0)
{
length[i]=INFINITY;
path[i]=0;
}
else
{
length[i]=gptr[s][i];
path[i]=s;
}
}
set[s]=1;
length[s]=0;

/*ITERATION PART */
temp=1;
while(temp)
{
c=0;
j=search_min(length,set,n);
set[j]=1;
for(i=1;i<=n;i++)
{
if(set[i]!=1)
{
if(gptr[i][j]!=0)
{
if(length[j]+gptr[i][j]<length[i])
{
length[i]=length[j]+gptr[i][j];
path[i]=j;
}
}
}
}
for(i=1;i<=n;i++)
{
if(set[i]==0)
c++;
}
if(c==0)
temp=0;
else
temp=1;
}
/*OUTPUT */
printf("length\tpath\n");
for(i=1;i<=n;i++)
printf("%d\t%d\n",length[i],path[i]);
printf("\n-------------------------------------------------------\n");
printf("\tPath\t\tLength\tShortest path \n");
printf("----------------------\n");
printf("From(sourcevertex) To \n");
printf("--------------------------------------------------------\n");
printf("\t%d\n",s);
for(i=1;i<=n;i++)
{
if(i!=s)
printf("\t\t%4d\t%2d",i,length[i]);
j=i;
while(j!=s)
{
printf("\t%d->%d",j,path[j]);
j=path[j];
}
printf("\n");
}
getch();
}
/* search min function */
search_min(int length[],int set[],int n)
{
int i,j,v,min=100;
for(i=1;i<=n;i++)
{
if(set[i]==0)
{
if(length[i]<min)
{
min=length[i];
v=i;
}
}
}
return v;
}
OUTPUT :
Enter No Of Vertexes
5
Enter Adjacency Matrix of a Graph
01600
10235
62042
03402
05220
Enter Source node
1
Length path
0 0
1 1
3 2
4 2
5 3
Path Length Shortest path From(source vertex) To
------------------------------------------------------------------------------
1 2 1 2->1
3 3 3->2 2->1
4 4 4->2 2->1
5 5 5->3 3->2 2->1

You might also like