c - find the maximum box width & length with the constraints -


Maximum length & amp; Width of a box

There are four sides of a box, the cost per meter is 2 width + 1 length is 2500 1 Length 1200 Length and width should be 0.1 meters.

Maximum width & Amp; And the length is both 100 meters, the follow-up is my code, it should be wrong, the tutor asks me to use two for the loop to find out, but I have no idea ... anybody can help is?

  #include & lt; Stdio.h & gt; Structure dimension {float length; Float width; }; Zero search box (float amount, straight dimension * dim) {/ * Enter your code here / float, which; Float area = 0; Flat max_rea = 1000; Float cost = 0; Float length = 100; Float width = 100; Cost = length * 2500 + (width * 2500 * 2) + length * 1200; While (cost & gt; zodiac) {length - = 0.1; Width - = 0.1; Printf ("% f", length); Printf ("% f", width); Cost = length * 2500 + (width * 2500 * 2) + length * 1200; If (cost and lt; zodiac) {printf ("% f \ n", length); Printf ("% f \ n", width); Cost = length * 2500 + (width * 2500 * 2) + length * 1200; Printf ("% f \ n", cost); break; }}} Int main () {struct Dimension dim; Search box (20000, and dim); }   

Your question is a bit unclear, but assume that based on what you said This should look like your attitude:

  #include & lt; Stdlib.h & gt; # Include & lt; Stdio.h & gt; # Include & lt; Stdint.h & gt; # Include & lt; Stdbool.h & gt; # Include & lt; Inttypes.h & gt; Typedef structure {uint32_t length, width; } Box_t; Bool box_size_from_cost (uint32_t icost, box_t * obox) {if (ICOSTAT (50 * 2500) + (50 * 1200)) returned incorrectly; Uint32_t width = 0; Uint32_t length [2] = {0}; Uint32_t costs [2] = {0}; ([Length] length = 0], length [0] ++, cost [0] + = 120) {length (length [1] = length [0], cost [1] = cost [0]; Width & lt; = 1000; width = 2, length [1] ++, cost [1] + = 250) {if (cost [1] == icost) {if (obox! = NULL) {obox-> width = Width; Obox-> gt; Length = length [1]; } Back true; } } } return false; } Int main (int arc, four ** argv) {if (argc & lt; 2) {printf ("use: box & lt; cost & gt; \ n"); Return EXIT_FAILURE; } Uint32_t cost; If (sscanf (argv [1], "%" SCNu32, and cost) == EOF) {printf ("Error: invalid cost parameter. \"); Return EXIT_FAILURE; } Box_t box; If (! Box_size_from_cost (cost, and box)) {printf ("no box size cost%" PRIu32 "\ n", cost); Return EXIT_FAILURE; } Printf ("cost"% .1fx% 1f one section% "PRIu32". \ N ", (box.width * 0.1), (box.length * 0.1), cost); Return EXIT_SUCCESS; }    

Comments