answersLogoWhite

0


Best Answer

#include <stdio.h>

#include <conio.h> //function to print the bins:

void printBins(float bins [500] [500],int items )

{

for (int j=1;j<=items;j++)

{

for (int i=1;i<=items;i++)

{

printf(" %1.3f",bins[i][j]);

}

printf("\n");

}

} int main()

{

int items, x=1,c=1, i=0, j=1, countOfBins=1;

float z,sum=0 ,inputitems[500], bin[500][500]; printf("Enter the number of items:");

scanf("%d", &items); //scanning how many elements the user wants to enter

if (items<=0)

{

printf("Can't bin-pack on zero elements");

getch();

}

else

{

do{

printf("\nEnter item number %d: ",x);

scanf ("%f",&z); //scanning the elements the user inputs if ((z<0)(z>1)) //assuming my bins range from 0 to 1 only

{

printf ("\nitem number %d is not in range of 0 to 1",x);

goto stop;

}

else //if all the inputs were in the correct range

{

inputitems[x]=z; //save my elements in an array called inputitems

x++;

}

}while (x<=items); //end of do-while statement

//technique number 1:

printf ("\nIn Next Fit online technique:");

loop:

while (c<=items)

{

if (sum+inputitems[c]<=1) //to check if you have any more room to fit in the bin

{

i++; //assuming that each row represents a bin

bin[i][j]=inputitems[c]; //place element from inputitems array into a 2D array called bin

sum += inputitems[c];

c++;

goto loop; //go back to the while statement to check condition

}

else

{

j++;

countOfBins++; //to count the number of bins we used

i=1;

sum=0;

bin[i][j]=inputitems[c];

sum += inputitems[c];

c++;

goto loop;

} } //end of while loop printf("\nNumber of bins used: %d \n", countOfBins);

printf("\nstructure of bin\n(FYI any empty rows shown, are equal to the number of items that you have entered)\n");

printBins(bin,items);//to print the bins used with their elements //end of first technique, can;t stop: getch();

}//end of very first else }//end of main //I could not figure out any of the other 4 techniques of Bin Packing... any help please?

User Avatar

Wiki User

16y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

15y ago

cout<<puday;

cin>>bilat;

This answer is:
User Avatar

User Avatar

Wiki User

15y ago

it is a memory management algorithm

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

tang ina mo ! ,,),,

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Code for first fit algorithm in C?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

C code to implement the file allocation algorithm?

yes we can do it,in c


C coding for cooley tukey fft algorithm?

hi.... for DIT fft algorithm, refer to this link, it has c-code for that. http://cnx.org/content/m12016/latest/


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.


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

Ronaldo! 'c' coding of Ricart-agarwala algorithm


How to write algorithm in c program?

Algorithms are created using pseudocode, which is a combination of natural language (such as English) and commonly understood programming concepts. Pseudocode is a machine-independent language, but it is far too abstract for a machine to understand. It is intended for humans only. As programmers, our job is to translate these algorithms into a form the machine can process in order to produce the required machine-dependent code. For this we use programming languages, such as C, C++ and Java. The more abstract the programming language, the easier it is to convert an algorithm into working code. Of all the high-level programming languages, C has the least amount of abstraction, however we can make use of third party libraries to increase the amount of abstraction, or we can use the language itself to create our own abstractions.

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.


C code to implement the file allocation algorithm?

yes we can do it,in c


Where do you get the exact source code in C that implements lossless compression algorithm?

The source code, in C, will depend on what type of lossless compression algorithm will be used. A source code should be available from various computer scientists in your area.


Write c code for extened euclid algorithm?

This is a request, not a question.


C coding for cooley tukey fft algorithm?

hi.... for DIT fft algorithm, refer to this link, it has c-code for that. http://cnx.org/content/m12016/latest/


How can i write pseudo code for C plus plus if i haven't even wrote the program yet?

You are going about this backwards. First, define the program. Second, describe its algorithm. Third, if needed, write pseudo code. (Sometime, algorithm and pseudo code is the same process.) Fourth, or third, write real code.


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.


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


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

Ronaldo! 'c' coding of Ricart-agarwala algorithm


How to write algorithm in c program?

Algorithms are created using pseudocode, which is a combination of natural language (such as English) and commonly understood programming concepts. Pseudocode is a machine-independent language, but it is far too abstract for a machine to understand. It is intended for humans only. As programmers, our job is to translate these algorithms into a form the machine can process in order to produce the required machine-dependent code. For this we use programming languages, such as C, C++ and Java. The more abstract the programming language, the easier it is to convert an algorithm into working code. Of all the high-level programming languages, C has the least amount of abstraction, however we can make use of third party libraries to increase the amount of abstraction, or we can use the language itself to create our own abstractions.


How you write C plus plus programming code for Lempel-Zip and Walch algorithm to compress files?

Lempel-Ziv-Welch (LZW) encoding is patented, thus we cannot show you a working example. However, the basic algorithm is well-documented on various websites including Wikipedia. If you can follow the algorithm, you can write the code. But you cannot distribute the code without the requisite licence.


What is algorithm in c?

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