answersLogoWhite

0

C program for worst fit algorithm?

Updated: 12/12/2022
User Avatar

Wiki User

12y ago

Best Answer

#include<iostream.h>

#include<conio.h>

#include<string.h>

int main()

{

unsigned int n,j,i,size[10],m,x=0,t;

int cho=1,ch;

system("cls");

cout<<"\t\t STORAGE PLACEMENT STRATEGIES\n";

cout<<"\tEnter the number of holes:";

cin>>n;

for(i=1;i<=n;i++)

{

cout<<"\n Enter The Size Of Hole "<<i<<":";

cin>>size[i];

}

while(cho==1)

{

cout<<"\nEnter the size of the incoming program:";

cin>>m;

cout<<"\nMenu";

cout<<"\n1.First Fit Strategy \n2.Best Fit Strategy";

cout<<"\n Enter your choice:";

cin>>ch;

x=0;

switch(ch)

{

case 1:

for(i=1;i<=n;i++)

{

if(size[i]>=m)

{

cout<<"\nYour program is placed in hole "<<i;

size[i]-=m;

x=i;

break;

}

}

if(x==0)

cout<<"There is no room for your program.";

break;

case 2:

unsigned int temp=0,pos=0,t1;

if(m<=size[1])

{

temp=size[1]-m;

pos=1;

}

else

temp=size[1];

for(i=2;i<=n;i++)

{

if(m<=size[i])

{

t1=size[i]-m;

if(temp>=t1)

{

temp=t1;

pos=i;

}

}

else temp=size[i];

}

if(pos==0)

cout<<"There is no room for your page.";

else

{

size[pos]=size[pos]-m;

cout<<"Your program is palced in hole "<<pos;

}

break;

case 4:

return;

}

cout<<"\nFree Storage List";

for(i=1;i<=n;i++)

cout<<"\nHole "<<i<<"\t\t"<<size[i];

cout<<"\n\nPress 1 to continue:";

cin>>cho;

}

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: C program for worst fit algorithm?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

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.


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


How does algorithm and c plus plus program get along?

They are bosom-friends.


C program algorithm for simple interest using while loop?

Not used


Can someone provide the C program for Prim's algorithm?

The C code for Prim's algorithm can be found in the following link. https://sites.google.com/site/itstudentjunction/lab-programming-solutions/data-structures-programs/program-to-find-minimal-spanning-tree-using--prims-algorithm


What is solution in c program?

The program itself is the solution. All programs are a solution to a given problem; that's the entire point of writing a program, to solve a problem. The program's algorithm specifies how the problem is solved and it's the programmer's job to convert that algorithm into working code.


How do you RSA algorithm c?

Perform encryption on the following PT using RSA and find the CT p = 3; q = 11; M = 5


Write a c program to find smallest among three using function with pointers?

Please visit http://talentsealed.blogspot.com/2009/10/to-find-smallest-among-three-using.htmlfor answer.


Does every algorithm have a c program?

Yes. More generally, every algorithm (defined as a sequence of finite steps to solve a problem that can be easily understood by a human) can be converted into machine code such that the algorithm can be understood by a machine. The C programming language is just one such method of converting algorithms into working machine code.


Algorithms to the given c plus plus programs?

The question is impossible to answer. You cannot determine an algorithm from a given program if the program is not actually given in the question. Please place the program in the discussion section.


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

Ronaldo! 'c' coding of Ricart-agarwala algorithm