answersLogoWhite

0

//here is a simple implementation of leaky bucket.

#include<stdio.h>

#include<stdlib.h>

#include<dos.h>

void main()

{

int i,packets[10],content=0,newcontent,time,clk,bcktsize,oprate;

for(i=0;i<5;i++)

{

packets[i]=rand()%10;

if(packets[i]==0) --i;

}

printf("\n Enter output rate of the bucket: \n");

scanf("%d",&oprate);

printf("\n Enter Bucketsize\n");

scanf("%d",&bcktsize);

for(i=0;i<5;++i)

{

if((packets[i]+content)>bcktsize)

{

if(packets[i]>bcktsize)

printf("\n Incoming packet size %d greater than the size of the bucket\n",packets[i]);

else

printf("\n bucket size exceeded\n");

}

else

{

newcontent=packets[i];

content+=newcontent;

printf("\n Incoming Packet : %d\n",newcontent);

printf("\n Transmission left : %d\n",content);

time=rand()%10;

printf("\n Next packet will come at %d\n",time);

for(clk=0;clk<time && content>0;++clk)

{

printf("\n Left time %d",(time-clk));

sleep(1);

if(content)

{

printf("\n Transmitted\n");

if(content<oprate)

content=0;

else

content=content-oprate;

printf("\n Bytes remaining : %d\n",content);

}

else

printf("\n No packets to send\n");

}

}

}

}

User Avatar

Wiki User

8y ago

What else can I help you with?

Related Questions

How can you implement Ricart and Agrawala's algorithm in c?

Ronaldo! 'c' coding of Ricart-agarwala algorithm


C code to implement the file allocation algorithm?

yes we can do it,in c


How do you write algorith of C programs?

There is no specific Hard and Fast rule for writing algorithm. The normal method is the following: 1. get a problem 2. find or invent an algorithm to solve it 3. implement the algorithm in a programming language (C, for example)


Write a program in C language to implement the apriori algorithm?

JavaScript is one program that has been written in C to implement the Apriori algorithm. There are also several other known programs available on the Internet that implement it as well.


What is the algorithm for determining the maximum of two numbers?

Compare two numbers, a and b. If a is greater than b then return a, otherwise return b. In C, we can implement this algorithm using the ternary operator (?:), as follows: return a&gt;b?a:b;


How do you write an Algorithm for a C plus plus Program?

You don't write an algorithm for a C++ program, unless you are documenting the C++ program after-the-fact. The normal procedure is to write the algorithm first, in a language independent fashion, and then translate that stated algorithm into C++ code, or into whatever language you wish.


What is algorithm in c?

Algorithm is a step by step process to solve a particular task.


Which book is suitable for c language?

1. A partition of a positive integer n is a sequence of positive integers that sum to n. Write an algorithm in psedocode and then implement the algorithm (in C) to print all non-increasing partitions of n. eg. If n=4 4 3 1 2 2 2 1 1 1 1 1 1


What is an algorithm for multiplying rational numbers?

The algorithm is A/B * C/D = AB/CD.


Can you give a C program about SJF algorithm?

no.


Program in c to develop an algorithm that prints the n value of algorithm?

reymond rillera reymond rillera


In banjo kazooie how do you access the cheat area?

In Treasure Trove Cove, when on the upper area right in front of the World Entry, move towards the sand castle that is under water. You will find a bucket named Leaky. Use your Down C move to fart eggs out into the bucket. The water level will go down and you can go into the castle to use the cheats.