100% Tested with Dartmouth x IMT Online Judge/Task Grader
Review
When you parse variable into a function block, the function block only copy the value and cannot access the real variable in the main block.
So we need to find the address of the variable to be able to change it from a function block.
You are participating in a game in which players collect points for various solved puzzles. In the end, the player with the highest score wins. You would like to know how far behind the highest-scoring person everyone else is in order to know whether you still have a chance at winning.
Please write a C program that uses a function "behind()" (which you also have to write) in order to help with this task. Your program should first read, from the user input, the number of players participating in the game. There are never more than 10 players in the game. Next, your program should read the current scores of each player and store them in an array. Then you should call the function behind(), to which you pass as a first argument, the array holding the player's scores, and as a second argument the number of players in the game. The function behind should replace the scores stored in the array with the number of points by which each individual player is behind the top-scoring player.
To help you out, the main function of the program has already been written, so your job is simply to write the function behind(), whose protype is also given to you.
Provided code
Example
Input
5
8 12 7 15 11Output
7
3
8
0
4
Solution
You are designing a new cookie recipe and are experimenting with different amounts of wet (water, oil) and dry (flour, sugar, cocoa powder) ingredients in order to get the proportions just right. All of these amounts are initially read from the user input, and the code to do so, along with all variable declarations, had already been completed. You are interested in the total amount of wet and dry ingredients used in the recipe as well as the ratio of these two quantities.
Take a look at the code that is already given to you. Your job is to add four lines of code, precisely where indicated by a comment such as
//Add one line here
Beneath each such line you will find an explanation of what precisely your line of code is supposed to do as well as what type of array addressing you are to use. Please read and follow these directions carefully. Do not change anything else in the code that is provided as our grading system will detect such changes and mark your solution as incorrect.
Example
Input
10.5 20.2
30.3 40.4 50.5Output
Total amount of wet ingredients: 30.70 grams.
Total amount of dry ingredients: 121.20 grams.
Ratio of wet to dry ingredients: 3.95.
New water amount: 15.35 grams, new oil amount: 15.35 grams.
Provided code & Solution
Your goal is to read a 68-word text from the input and then print it to the screen backwards. Individual words do not have to be spelled backwards, but rather your program should print out the last word first, then the second-to-last word, etc. No word has more than 40 characters.
Example
Input
Science Computer on Papers Selected Knuth, Ervin Donald ― correct." be will results the that reader a convince to and works algorithm an way the communicate to concepts, mathematical as well as forms literary and aesthetic traditional with works who essayist an ideally is programmer A clearly. them understand can beings human that so and quickly them perform can machines computing that so written are programs best "TheOutput
"The best programs are written so that computing machines can perform them quickly and so that human beings can understand them clearly. A programmer is ideally an essayist who works with traditional aesthetic and literary forms as well as mathematical concepts, to communicate the way an algorithm works and to convince a reader that the results will be correct." ― Donald Ervin Knuth, Selected Papers on Computer Science
heap precompiled before the stack
Malloc is in heap and ptr in stack
After freeing the memory, the value is still reserved. It can be overwrite or if you lucky, access it with the same pointer/address
Dynamic allocation (with pointer arithmetic)
Example
dynamically allocate memory for strings
You are working on programming a toaster (again!). The user of the toaster has the option to have their bread toasted "light" or "dark", and you are working on implementations in different languages of this particular setting. For example, in the German model, the settings would be stored as "hell" and "dunkel" instead. In order to be as efficient as possible with the use of the limited memory on the computer chip in the toaster you need to write a function "allocateString()" that allocates memory for strings (and you will then use this function to allocate just enough memory to store the settings on a particular model).
This function "allocateString()" takes as argument an integer (of type int), representing the number of characters to allocate space for in memory. The function returns a pointer (of type char *), containing the address of the allocated memory. The function should use memory allocation to reserve the correct amount of space in memory. In order to receive credit for your solution you need to use sizeof (char) in this line, even if sizeof (char) returns 1.
In your main() function you should call the function allocateString() twice: once for the label containing the "light" setting and once for the "dark" setting. You are provided with some code already that explains precisely what you need to do. Please do not change the code that has been given to you. Please only change those lines that say "// add a line of code…".
Example
Input
4 6
hell
dunkelOutput
Local settings: hell - dunkel
Provided code & Solution
You have been hired to assist firefighters locate wildfires in a large geographic area. The area is divided into smaller zones. Each zone is scanned via satellite for its average temperature. If a zone has an average temperature strictly greater than 1000°F, we assume there is a fire in that zone. If the temperature is between 100 degrees (included) and 1000 degrees (included), we have to further investigate, so it becomes a "zone to watch."
The large geographic area you are watching is a rectangle with a certain length and width, each given in terms of zones. For example, if the area to be scanned has a length of 6 and width of 9 then it will be divided into 6*9 zones:
––length = 6––
[ ][ ][ ][ ][ ][ ] |
[ ][ ][ ][ ][ ][ ] w
[ ][ ][ ][ ][ ][ ] i
[ ][ ][ ][ ][ ][ ] d
[ ][ ][ ][ ][ ][ ] t
[ ][ ][ ][ ][ ][ ] h
[ ][ ][ ][ ][ ][ ] =
[ ][ ][ ][ ][ ][ ] 9
[ ][ ][ ][ ][ ][ ] |
Because your program will be used for a variety of geographic areas (each with its own length and width) your program needs to dynamically allocate the memory for the number of zones it is to handle (vertically and horizontally).
To do so, you must use the two following functions without changing the code in them:
The function allocateIntArray() will be used to allocate the space required to store the average temperatures in one row of zones, that is, an array of integers. The function therefore returns a pointer to such an array of integers.
The function allocateIntStarArray() will be used to allocate an array of pointers, each of which will store a pointer to a row of integers (temperatures of zones). That is, the function returns a pointer to an array of pointers. Each cell of this array will point to an array of integers containing the temperature values for the zones.
The inputs of the program are first the length, then the width of an area, then the average temperatures of all zones, row by row.
Please remember to free the memory you have allocated.
The output should pinpoint the possible zones with fires with [X] and the watch zone with a [*], the other zone are displayed with [ ].
Look at the example at the bottom and make sure to format your output in the exact same way.
Input:
6
9
70 71 70 72 70 69
71 73 68 71 73 72
70 71 70 76 1900 78
69 71 100 800 75 71
70 70 71 79 70 69
70 71 112 1005 75 72
70 71 70 900 70 70
72 70 70 72 70 69
73 74 73 72 70 70
Output:
[ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][X][ ]
[ ][ ][s][s][ ][ ]
[ ][ ][ ][ ][ ][ ]
[ ][ ][s][X][ ][ ]
[ ][ ][ ][s][ ][ ]
[ ][ ][ ][ ][ ][ ]
[ ][ ][ ][ ][ ][ ]