CN Prac 3

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Practical 3

Name : Ansh Agrawal


Roll No – 20
Section - A
Aim : Implement CRC using c program

Code :
1]
#include <stdio.h>
#include <stdlib.h>
int main() {
int i, j, num[10], divs[10], quo[10], rem[10], temp, num2[10], rem2[10];
printf("Enter your mgs(6bit): ");
for (i = 0; i < 6; i++) {
scanf("%d", &num[i]);
num2[i] = num[i];
}
printf("\nEnter your divisor(4bit): ");
for (i = 0; i < 4; i++) {
scanf("%d", &divs[i]);
}
for (i = 6; i < 9; i++) {
num[i] = 0;
}
for (i = 0; i < 6; i++) {
temp = i;
if (num[i] == 0) {
quo[i] = 0;
} else {
quo[i] = 1;
for (j = 0; j <= 4; j++) {
if (num[temp] == divs[j]) {
num[temp] = 0;
rem[j] = 0;
} else {
num[temp] = 1;
rem[j] = 1;
}
temp = temp + 1;
}
}
}
printf("\n Quotient =");
for (int i = 0; i < 6; i++) {
printf("%d", quo[i]);
}
printf("\n Remainder =");
for (int i = 1; i < 4; i++) {
printf("%d", rem[i]);
}
num2[6] = rem[1];
num2[7] = rem[2];
num2[8] = rem[3];
for (int i = 0; i < 6; i++) {
temp = i;
if (num2[i] == 0) {
quo[i] = 0;
} else {
quo[i] = 1;
for (int j = 0; j <= 4; j++) {
if (num2[temp] == divs[j]) {
num2[temp] = 0;
rem2[j] = 0;
} else {
num2[temp] = 1;
rem2[j] = 1;
}
temp = temp + 1;
}
}
}
printf("\n New remainder to check message = ");
for (int i = 1; i < 4; i++) {
printf("%d", rem2[i]);
}
return 0;
}

Output :
2]
Code:
#include<stdio.h>
int main() {
int framesize, sent = 0, ack, i;
printf("Enter the number of frames: ");
scanf("%d", &framesize);
while (1) {
for (i = 0; i < framesize; i++) {
printf("Frame %d has been transmitted.\n", sent);
sent++;
if (sent == framesize)
break;
}
printf("\nPlease enter the last acknowledgement received: ");
scanf("%d", &ack);
if (ack >= framesize) {
break;
} else {
sent = ack;
}
}
return 0;
}

Output :

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy