0% found this document useful (0 votes)
3 views

Alpha

The document contains two C programs: the first encodes 4 bits of data using parity bits for error detection and correction, while the second implements the Distance Vector Routing algorithm to find the shortest paths in a network based on a cost matrix. The sender program calculates parity bits and displays encoded data, and the receiver program checks for errors and corrects them if necessary. The routing program reads a cost matrix, computes the shortest paths, and displays the results for each router.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Alpha

The document contains two C programs: the first encodes 4 bits of data using parity bits for error detection and correction, while the second implements the Distance Vector Routing algorithm to find the shortest paths in a network based on a cost matrix. The sender program calculates parity bits and displays encoded data, and the receiver program checks for errors and corrects them if necessary. The routing program reads a cost matrix, computes the shortest paths, and displays the results for each router.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

4)

Sender Code:

#include <stdio.h>
#include <math.h>
int main()
{
int data[10];
int data_at_reciever [10];
int c, cl, c2, c3,i;
printf ("Enter 4 bits of data one by one \n");
scanf("%d", & data[0]);
scanf("%d", & data[1]);
scanf("%d", & data[2]);
scanf("%d", & data[4]);
data [6] = data[0]^ data[2]^ data[4];
data [5] = data[0]^ data[1]^ data[4];
data [3] = data[0]^ data[1]^ data[2];
printf("\n Encoded data is \n");
for(i=0;i<7;i++)
{
printf("%d", data [i]);
}
return 0;
}

Receiver Code:

#include<stdio.h>
int main()
{
int received [7],c;
printf ("Enter received 7bits :\n");
for (int i=0;i<7;i++)
scanf ("%d",& received[i]);
c = (received[6]^received[4]^received[2]^received[0])*1+
(received[5]^received[4]^received[1]^received[0])*2+
(received[3]^received[2]^received[1]^received[0])*4;
if (c == 0)
{
printf ("No error in transmission /n");
}
else
{
printf ("Error at position ; %d \n",c);
received [7-c]^=1;
printf ("corrected data :");
for (int i=0;i<7;i++)
printf ("%d , received [i]");
}
return 0;
}

11.)
#include <stdio.h>
#include <limits.h>
#define MAX 20
#define INF INT_MAX
struct node
{ unsigned dist[MAX], from[MAX]; } rt[MAX];

int main() {
int dmat[MAX][MAX], n, i, j, k, count;
printf("Enter number of nodes: ");
scanf("%d", &n);
printf("Enter cost matrix (%d for no direct connection):\n", INF);
for (i = 0; i < n; i++)
for (j = 0; j < n; j++) {
scanf("%d", &dmat[i][j]);
dmat[i][j] = (dmat[i][j] == 0 && i != j) ? INF : dmat[i][j];
rt[i].dist[j] = dmat[i][j], rt[i].from[j] = j;
}
do {
count = 0;
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
for (k = 0; k < n; k++)
if (rt[i].dist[j] > dmat[i][k] + rt[k].dist[j])
rt[i].dist[j] = dmat[i][k] + rt[k].dist[j], rt[i].from[j] =
k, count++;
} while (count);
for (i = 0; i < n; i++) {
printf("\nRouter %d:\n", i + 1);
for (j = 0; j < n; j++)
printf(rt[i].dist[j] == INF ? "\tNode %d unreachable\n" : "\tNode %d
via %d Distance %d\n", j + 1, rt[i].from[j] + 1, rt[i].dist[j]);
}
return 0;
}

You might also like