Ex 8

 # #include<stdio.h>

#include<stdlib.h>

#define MIN(x,y) (x>y)?y:x

int main()

{

 int orate,drop=0,cap,x,count=0,inp[10]={0},i=0,nsec,ch;

 printf("\n enter bucket size : ");

scanf("%d",&cap);

 printf("\n enter output rate :");

 scanf("%d",&orate);

 do{

printf("\n enter number of packets coming at second %d :",i+1);

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

 i++;

 printf("\n enter 1 to contiue or 0 to quit..........");

 scanf("%d",&ch);

 }while(ch);

 nsec=i;

printf("\n second \t recieved \t sent \t dropped \t remained \n");

 for(i=0;count || i<nsec;i++)

 {

 printf(" %d",i+1);

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

 printf(" \t %d\t ",MIN((inp[i]+count),orate));

 if((x=inp[i]+count-orate)>0)

 {

 if(x>cap)

 {

 count=cap;

 drop=x-cap;

 }

 else

 {

 count=x;

 drop=0;

 }

 }

 else

 {

 drop=0;

 count=0;

 }

 printf(" \t %d \t %d \n",drop,count);

 }

return 0;

} 

Output

 enter bucket size : 50

 enter output rate :120

 enter number of packets coming at second 1 :200

 enter 1 to contiue or 0 to quit..........1

 enter number of packets coming at second 2 :85

 enter 1 to contiue or 0 to quit..........0


 Second received sent dropped remained 

 1 200 120 30 50 

 2 85 120 0 15 

 3 0 15 0 0

Comments

Popular posts from this blog

Some code cn

Char count

Fork