-
-
Save ishank-dev/35802c0bbcd4242d9b06d8727e231a7c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<stdlib.h> | |
int packets[10]; | |
void main(){ | |
int orate = 2,capacity = 5,contain = 0,dropped=0; | |
for (int i = 0; i < 5; ++i) | |
{ | |
packets[i] = rand()%10; | |
} | |
printf("Iteration\tReceived\tSent\tDropped\tContains\n"); | |
for (int i = 0;contain || i < 5; ++i) | |
{ | |
printf("%d",i ); | |
printf("\t\t%d",packets[i] ); | |
if(contain+packets[i]<orate) | |
printf("\t\t%d",contain+packets[i] );//last iteration when the bucket is emptying with no incoming packets | |
else | |
printf("\t\t%d",orate); | |
int incoming = contain+packets[i]-orate; | |
if(incoming>0){ | |
if(incoming>capacity){ | |
contain = capacity; | |
dropped = incoming - capacity; | |
} | |
else{ | |
contain = incoming; | |
dropped = 0; | |
} | |
} | |
else{ | |
dropped = 0; | |
contain = 0; | |
} | |
printf("\t%d\t%d \n",dropped,contain); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment