-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgobackn.c
42 lines (42 loc) · 1.02 KB
/
gobackn.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main()
{
int numofframes, windowsize;
int tr = 0;
srand(time(NULL));
printf("Enter the number of frames : ");
scanf("%d", &numofframes);
printf("Enter the Window Size : ");
scanf("%d", &windowsize);
int i = 1;
while (i <= numofframes)
{
int x = 0;
for (int j = i; j < i + windowsize && j <= numofframes; j++)
{
printf("Sent Frame %d \n", j);
tr++;
}
for (int j = i; j < i + windowsize && j <= numofframes; j++)
{
int flag = rand() % 2;
if (!flag)
{
printf("%d : Acknowledged! \n", j);
x++;
}
else
{
printf("Frame %d Not Received \n", j);
printf("Retransmitting Window \n");
break;
}
}
printf("\n");
i += x;
}
printf("Total number of transmissions : %d \n", tr);
return 0;
}