{"id":5378,"date":"2020-09-13T19:08:54","date_gmt":"2020-09-13T17:08:54","guid":{"rendered":"https:\/\/blue.pri.ee\/ttu\/?p=5378"},"modified":"2025-10-03T10:16:28","modified_gmt":"2025-10-03T08:16:28","slug":"4-lab-arrays","status":"publish","type":"post","link":"https:\/\/blue.pri.ee\/ttu\/labs\/4-lab-arrays\/","title":{"rendered":"PR1EN5: Arrays"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/4-lab-arrays\/#Lab_content\" >Lab content<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/4-lab-arrays\/#Tasks\" >Tasks<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/4-lab-arrays\/#Task_1_part_1_W05-1_Finding_extreme_values\" >Task 1 part 1 [W05-1]: Finding extreme values<\/a><ul class='ez-toc-list-level-5' ><li class='ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/4-lab-arrays\/#Requirements\" >Requirements<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/4-lab-arrays\/#Workflow_guide\" >Workflow guide<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/4-lab-arrays\/#Testing\" >Testing<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/4-lab-arrays\/#Task_1_part_2_W05-2_positions_and_repetition_count\" >Task 1 part 2 [W05-2]: positions and repetition count<\/a><ul class='ez-toc-list-level-5' ><li class='ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/4-lab-arrays\/#Requirements-2\" >Requirements<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/4-lab-arrays\/#Workflow_guide-2\" >Workflow guide<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/4-lab-arrays\/#Testing-2\" >Testing<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/4-lab-arrays\/#Extra_task_1_W05-3_Statistics\" >Extra task 1 [W05-3]: Statistics<\/a><ul class='ez-toc-list-level-5' ><li class='ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/4-lab-arrays\/#Testing-3\" >Testing<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/4-lab-arrays\/#Extra_task_2_W05-4_n_numbers_without_VLA\" >Extra task 2 [W05-4]: n numbers without VLA<\/a><ul class='ez-toc-list-level-5' ><li class='ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/4-lab-arrays\/#Requirements-3\" >Requirements<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/4-lab-arrays\/#Testing-4\" >Testing<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/4-lab-arrays\/#After_the_class_you_should\" >After the class, you should<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/4-lab-arrays\/#Additional_content\" >Additional content<\/a><\/li><\/ul><\/nav><\/div>\n<h3><span class=\"ez-toc-section\" id=\"Lab_content\"><\/span><strong>Lab content<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li><strong><a href=\"https:\/\/blue.pri.ee\/ttu\/programming-i\/samples\/math-h-library\/\">Math.h library introduction<\/a><\/strong>\n<ul>\n<li>Type casting<\/li>\n<li>Floating point precision<\/li>\n<\/ul>\n<\/li>\n<li>Slides:<strong>\u00a0<a href=\"https:\/\/blue.pri.ee\/ttu\/files\/iax0583\/slaidid-en\/05_Arrays.pdf\">Arrays<\/a><\/strong><\/li>\n<li>Additional example: <a href=\"https:\/\/blue.pri.ee\/ttu\/programming-i\/samples\/distance-converter-arrays-with-functions\/\"><strong>distance converter<\/strong><\/a><\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Tasks\"><\/span>Tasks<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The task for this week is separated into two parts. First complete the first part and present your solution. Then improve your existing solution by solving the second part of the task and present the solution again. The base task can be extended by two extra task.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"Task_1_part_1_W05-1_Finding_extreme_values\"><\/span>Task 1 part 1 [W05-1]: Finding extreme values<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>Part 1 will be solved as a UML activity diagram in the class. You will have to implement the algorithm as a program based on the starter code presented, following the logic of the algorithm. In part 1, you will have four functions besides <span class=\"lang:c highlight:0 decode:true crayon-inline\">main()<\/span>\u00a0!<\/p>\n<p><strong>Download the starter code: <a href=\"https:\/\/blue.pri.ee\/ttu\/files\/iax0583\/aluskoodid\/5_minmax_template.c\">https:\/\/blue.pri.ee\/ttu\/files\/iax0583\/aluskoodid\/5_minmax_template.c<\/a><\/strong><\/p>\n<h5><span class=\"ez-toc-section\" id=\"Requirements\"><\/span><strong>Requirements<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h5>\n<ul>\n<li>Part 1 must match the logic described in the UML activity diagram<\/li>\n<li>You have to complete all 4 functions that are described in the starter code as comments and use them in your solution. You will need to also add missing parts like macros, variable declarations, function prototypes and function calls.<\/li>\n<li>User will enter 6 numbers from the keyboard, which will be stored in an array.<\/li>\n<li>The process of entering the numbers must be clear. You must show which number and out of many they are currently entering<\/li>\n<li>You need to find and print the smallest number in the array. The smallest value needs to be found in a user-defined function, returned and printed in main().<\/li>\n<li>You need to find and print the greatest number in the array. The greatest value needs to be found in a user-defined function, returned and printed in main().<\/li>\n<li>You need to print out the original array. This must be done in a separate function.<\/li>\n<\/ul>\n<h5><span class=\"ez-toc-section\" id=\"Workflow_guide\"><\/span>Workflow guide<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<p>NB! For every function, first read the function comment to understand what the function does, which inputs are needed as parameters and what the result (return) has to be. Each function must be implemented below the comment.<\/p>\n<ol>\n<li>Start by completing <span class=\"lang:c highlight:0 decode:true crayon-inline\">ReadIntArray()<\/span>\u00a0 function given in the starter code. This is the first function after <span class=\"lang:c highlight:0 decode:true crayon-inline \">main()<\/span>\u00a0.<br \/>\nYou will need to write a loop that on each iteration, prints the prompt and then reads the value, storing it into the array.\u00a0 There will be a very similar example done in the lab as live code.<\/li>\n<li>To test it, we need to call the function. For this, we need to declare the array in the main function and then call the function, passing it the array and its length.<br \/>\nAssuming you have a macro called <span class=\"lang:c highlight:0 decode:true crayon-inline\">NUM_CNT<\/span>\u00a0 and an array called <span class=\"lang:c highlight:0 decode:true crayon-inline \">numbers<\/span> , the function call will look like\u00a0 <span class=\"lang:c highlight:0 decode:true crayon-inline \">ReadIntArray(numbers, NUM_CNT);<\/span><br \/>\nTest and see if your reading code works.<\/li>\n<li>To validate our results, we should print what we got.\u00a0 Complete the function <span class=\"lang:c highlight:0 decode:true crayon-inline\">PrintArray()<\/span>\u00a0\u00a0and call it from <span class=\"lang:c highlight:0 decode:true crayon-inline\">main()<\/span> .\u00a0 Note that this time you have to set the parameters and return value yourself.<\/li>\n<li>Now you have two more functions to complete. Both are specified as function comments in the starter code. Finish the functions, call them out and print the results.<br \/>\n<strong>NB! The functions finding min and max values are not allowed to have side effects. Results must be printed in the main() function.<\/strong><\/li>\n<\/ol>\n<h5><span class=\"ez-toc-section\" id=\"Testing\"><\/span>Testing<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<p><strong>Test 1:<\/strong> min first, max last<\/p>\n<pre class=\"theme:cisco-router toolbar:1 nums:false lang:default highlight:0 decode:true\" title=\"Sample 1: Min ind 0\">Enter number 1 \/ 6: 1\r\nEnter number 2 \/ 6: 2\r\nEnter number 3 \/ 6: 3\r\nEnter number 4 \/ 6: 4\r\nEnter number 5 \/ 6: 5\r\nEnter number 6 \/ 6: 6\r\n\r\nEntered numbers:\r\n1 2 3 4 5 6\r\n\r\nMin value is 1\r\nMax value is 6<\/pre>\n<p><strong>Test 2:<\/strong> min last, max first<\/p>\n<pre class=\"theme:cisco-router toolbar:1 nums:false lang:default highlight:0 decode:true \" title=\"Sample 2: max is ind 0\">Enter number 1 \/ 6: 6\r\nEnter number 2 \/ 6: 5\r\nEnter number 3 \/ 6: 4\r\nEnter number 4 \/ 6: 3\r\nEnter number 5 \/ 6: 2\r\nEnter number 6 \/ 6: 1\r\n\r\nEntered numbers:\r\n6 5 4 3 2 1\r\n\r\nMin value is 1\r\nMax value is 6<\/pre>\n<p><strong>Test 3:<\/strong> Min value is negative. Both min and max are in the middle of the array.<\/p>\n<pre class=\"theme:cisco-router toolbar:1 nums:false lang:default highlight:0 decode:true\" title=\"Sample 2: min and max in the middle\">Enter number 1 \/ 6: 1\r\nEnter number 2 \/ 6: 2\r\nEnter number 3 \/ 6: 3\r\nEnter number 4 \/ 6: 4\r\nEnter number 5 \/ 6: -933\r\nEnter number 6 \/ 6: 1\r\n\r\nEntered numbers:\r\n1 2 3 4 -933 1\r\n\r\nMin value is -933\r\nMax value is 4<\/pre>\n<h4><span class=\"ez-toc-section\" id=\"Task_1_part_2_W05-2_positions_and_repetition_count\"><\/span>Task 1 part 2 [W05-2]: positions and repetition count<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>In part 1 you found the extreme values from the array. In part 2, you need to find the positions of those values and how many times they occurred.<\/p>\n<h5><span class=\"ez-toc-section\" id=\"Requirements-2\"><\/span>Requirements<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<ul>\n<li>Print all positions of the greatest value in the array. Printing must be done in a separate function, outside of <span class=\"lang:c highlight:0 decode:true crayon-inline \">main()<\/span>\u00a0.<\/li>\n<li>Print all positions of the smallest value in the array.\u00a0Printing must be done in a separate function, outside of <span class=\"lang:c highlight:0 decode:true crayon-inline \">main()<\/span>\u00a0.<\/li>\n<li>Print how many occurrences the min and max value had. Results must be found in a separate function and printed out in <span class=\"lang:c highlight:0 decode:true crayon-inline\">main()<\/span>\u00a0.<\/li>\n<li>Positions printed must match the way you asked the user for input!<\/li>\n<li>Implement the two functions specified under Workflow Guide. Reuse the created functions for both min and max values.<\/li>\n<\/ul>\n<h5><span class=\"ez-toc-section\" id=\"Workflow_guide-2\"><\/span>Workflow guide<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<p>To solve this part of the task, you need to create two functions. Both functions are given to you as function comments. You will need to implement the functions based on the comment.<\/p>\n<p>First function will be to print out all the positions of the array. To do this, you need to loop through the array and every time you find the\u00a0 number you are searching for (e.g. min value), you need to print out the position you are currently at in the loop! So in total, the function will consist of a loop, a conditional statement and a print statement &#8211; that&#8217;s it!<\/p>\n<p><strong>You need to reuse this function for both min and max!\u00a0<\/strong>Note that the text describing the results should be printed in main (i.e. &#8220;Min value position(s): &#8220;)<\/p>\n<pre class=\"toolbar:2 lang:c highlight:0 decode:true\">\/**\r\n * Description:  Prints all positions of val in the array. Shows positions \r\n *               (starting from 1), instead of indexes. \r\n * \r\n * Parameters:   nums - values that are checked\r\n *               len - length of the array\r\n *               val - value for which the positions will be printed\r\n * \r\n * Return:       -\r\n *\/<\/pre>\n<p>After implementing this function, check that the code works before proceeding to the next function!<\/p>\n<p>The second function will be very similar to the first one. In this one, you need to\u00a0<strong>count<\/strong> instead of print. Once finished, just return the result you counted and print it in <span class=\"lang:c highlight:0 decode:true crayon-inline\">main()<\/span> .\u00a0\u00a0<strong>There is no printing of the result in the function itself, i.e. function should have no side effects!<\/strong><\/p>\n<pre class=\"toolbar:2 lang:c highlight:0 decode:true \">\/**\r\n * Description:  Counts the number of times val is present in the array\r\n * \r\n * Parameters:   nums - values that are checked\r\n *               len - length of the array\r\n *               val - value to search for\r\n * \r\n * Return:       number of times val occurred in array\r\n *\/<\/pre>\n<h5><span class=\"ez-toc-section\" id=\"Testing-2\"><\/span>Testing<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<p><strong>Test 1: only 1 occurrence of min and max<\/strong><\/p>\n<pre class=\"theme:cisco-router toolbar:1 nums:false lang:default highlight:0 decode:true\" title=\"Sample: min and max single occurrence\">Enter number 1 \/ 6: 10\r\nEnter number 2 \/ 6: 11\r\nEnter number 3 \/ 6: 12\r\nEnter number 4 \/ 6: 13\r\nEnter number 5 \/ 6: 14\r\nEnter number 6 \/ 6: 15\r\n\r\nEntered numbers:\r\n10 11 12 13 14 15\r\n\r\nMin value is 10\r\nMin value position(s): 1\r\nMin value occurred 1 time\r\n\r\nMax value is 15\r\nMax value position(s): 6\r\nMax value occurred 1 time<\/pre>\n<p><strong>Test 2: Multiple occurrences of min and max<\/strong><\/p>\n<pre class=\"theme:cisco-router toolbar:1 nums:false lang:default highlight:0 decode:true\" title=\"Sample: min and max multiple occurrence\">Enter number 1 \/ 6: 10\r\nEnter number 2 \/ 6: 13\r\nEnter number 3 \/ 6: 12\r\nEnter number 4 \/ 6: 10\r\nEnter number 5 \/ 6: 13\r\nEnter number 6 \/ 6: 13\r\n\r\nEntered numbers:\r\n10 13 12 10 13 13\r\n\r\nMin value is 10\r\nMin value position(s): 1 4\r\nMin value occurred 2 times \r\n\r\nMax value is 13\r\nMax value position(s): 2 5 6\r\nMax value occurred 3 times<\/pre>\n<h4><span class=\"ez-toc-section\" id=\"Extra_task_1_W05-3_Statistics\"><\/span>Extra task 1 [W05-3]: Statistics<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>In this extra task, we will calculate 3 more results from the data in the array.<\/p>\n<p><span style=\"font-size: 18px; font-weight: bold;\">Requirements<\/span><\/p>\n<ul>\n<li>Implement 3 functions, that will find the sum, product and arithmetic<\/li>\n<li>Calculating arithmetic mean should reuse the function to calculate sum so you wouldn&#8217;t copy-paste code<\/li>\n<li>All 3 functions must use the array and the length of the array as their parameters<\/li>\n<li>All functions must calculate the result and return the answer. Result must be printed out in <span class=\"lang:c highlight:0 decode:true crayon-inline \">main()<\/span><\/li>\n<li>Display the arithmetic mean with 3 places after the comma<\/li>\n<\/ul>\n<h5><span class=\"ez-toc-section\" id=\"Testing-3\"><\/span>Testing<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<p>The biggest stumbling block in this task is getting the arithmetic mean correct. Let&#8217;s test it.<\/p>\n<pre class=\"theme:cisco-router toolbar:1 nums:false lang:default highlight:0 decode:true\" title=\"Sample: precision test for avg\">Enter number 1 \/ 6: 1\r\nEnter number 2 \/ 6: 1\r\nEnter number 3 \/ 6: 1\r\nEnter number 4 \/ 6: 1\r\nEnter number 5 \/ 6: 1\r\nEnter number 6 \/ 6: 3\r\n\r\nEntered numbers:\r\n1 1 1 1 1 3\r\n\r\nMin value is 1\r\nMin value position(s): 1 2 3 4 5\r\nMin value occurred 5 times\r\n\r\nMax value is 3\r\nMax value position(s): 6\r\nMax value occurred 1 time\r\n\r\nSum is 8\r\nProduct is 3\r\nArithmetic mean is 1.333<\/pre>\n<h4><span class=\"ez-toc-section\" id=\"Extra_task_2_W05-4_n_numbers_without_VLA\"><\/span>Extra task 2 [W05-4]: n numbers without VLA<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>To make the program a bit more useful, we&#8217;ll allow the user to enter the amount of numbers the program can work with.<\/p>\n<p>NB! Even though most C compilers work with VLAs (variable length array), not all versions of the C standard define it as mandatory property of the C language. Depending on the compiler, it may fail to work.<\/p>\n<p>In addition, there are also downsides to performance of VLAs, which make them less preferred in performance-oriented tasks. In short, VLAs translate to more complex assembly code which takes more CPU cycles to execute. In addition, if no other checks are performed, it is extremely easy to crash programs using VLAs (e.g. I want to enter 10 000 000 numbers).<\/p>\n<p>Because of this, you are allowed to declare an array where the size is defined by another variable (e.g.\u00a0 <span class=\"lang:default decode:true crayon-inline\">int numbers[numberCount];<\/span> , where <span class=\"lang:c highlight:0 decode:true crayon-inline \">numberCount<\/span>\u00a0 is a variable specified by the user during runtime). The universal solution based on the standard is by using dynamic memory allocation, but that is a topic for Programming 2.<\/p>\n<p>For the purpose of this lab task, you will decide on a maximum size that the user can enter and use that as the upper bound. This means, that most likely there will be unused slots in the array. However since our program is small, this won&#8217;t cause us problems.<\/p>\n<p>Note, that in general, use of VLAs is not forbidden in this course. The limitation is for this task.<\/p>\n<h5><span class=\"ez-toc-section\" id=\"Requirements-3\"><\/span>Requirements<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<ul>\n<li>Allow the user to specify how many numbers they will be entering<\/li>\n<li>Limit the program so that the user cannot enter a number greater than the size of the array defined.<\/li>\n<li>Asking of the size from the user must be handled by a function you create for this task. The function will only be allowed to return if the input is within the specified limits.\n<ul>\n<li>Use parameters to specify the limits<\/li>\n<li>The function you create should be reusable in other similar situations (but with different limits).<\/li>\n<\/ul>\n<\/li>\n<li>You can choose the &#8220;reasonable&#8221; size of the array yourself (e.g. 50 members).<\/li>\n<li>Create error handling for situations where the user enters the array size which is either too big or small.<\/li>\n<li>Usage of VLA (variable length array) is forbidden in this task!<\/li>\n<li>NB! Make sure to update your coding style &#8211; variables cannot be written in the same style as macros!<\/li>\n<\/ul>\n<h5><span class=\"ez-toc-section\" id=\"Testing-4\"><\/span>Testing<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<p>Make sure to test the following<\/p>\n<ul>\n<li>Minimal allowed number count.<\/li>\n<li>Maximum allowed number count.<\/li>\n<li>Number count that is different from the original task.<\/li>\n<\/ul>\n<pre class=\"theme:cisco-router toolbar:1 nums:false lang:default highlight:0 decode:true\" title=\"Sample: testing of user entered n\">Enter number count (up to 50): 127\r\nError! Invalid number count!\r\nEnter number count (up to 50): 3\r\n\r\nEnter number 1 \/ 3: 5\r\nEnter number 2 \/ 3: 1\r\nEnter number 3 \/ 3: 2\r\n\r\nEntered numbers:\r\n5 1 2\r\n\r\nMin value is 1\r\nMin value position(s): 2\r\nMin value occurred 1 time\r\n\r\nMax value is 5\r\nMax value position(s): 1\r\nMax value occurred 1 time\r\n\r\nSum is 8\r\nProduct is 10\r\nArithmetic mean is 2.667<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"After_the_class_you_should\"><\/span><span id=\"After_the_class,_you_should_be_able_to\" class=\"ez-toc-section\"><\/span><strong>After the class, you should<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>Know how to perform type casting<\/li>\n<li>Know about floating point precision and problems with it<\/li>\n<li>Know how fixed point and floating point number representation works<\/li>\n<li>Know about math library and how to use it, including how to set the compiler flag, if necessary<\/li>\n<li>What an array is<\/li>\n<li>How to declare an array<\/li>\n<li>How to initialize arrays<\/li>\n<li>How to index each member of the array<\/li>\n<li>How to index through an array using loops<\/li>\n<li>How to find the extreme values in an array<\/li>\n<li>How to pass arrays to functions<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Additional_content\"><\/span><span id=\"Additional_content\" class=\"ez-toc-section\"><\/span><strong>Additional content<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>C math library:<br \/>\n<strong><a href=\"http:\/\/www.cplusplus.com\/reference\/cmath\/\">http:\/\/www.cplusplus.com\/reference\/cmath\/<\/a><\/strong><\/li>\n<li>0.1 + 0.2 in various programming languages:<br \/>\n<strong><a href=\"https:\/\/0.30000000000000004.com\/\">https:\/\/0.30000000000000004.com<\/a><\/strong><\/li>\n<li>Floating Point Numbers \u2013 Computerphile<br \/>\n<strong><a href=\"https:\/\/www.youtube.com\/watch?v=PZRI1IfStY0\">https:\/\/www.youtube.com\/watch?v=PZRI1IfStY0<\/a><\/strong><\/li>\n<li>Floating point and fixed point representation<br \/>\n<strong><a href=\"https:\/\/www.tutorialspoint.com\/fixed-point-and-floating-point-number-representations\">https:\/\/www.tutorialspoint.com\/fixed-point-and-floating-point-number-representations<\/a><\/strong><\/li>\n<li>Type casting (conversion)<br \/>\n<strong><a href=\"https:\/\/www.geeksforgeeks.org\/type-conversion-c\/\">https:\/\/www.geeksforgeeks.org\/type-conversion-c\/<\/a><\/strong><\/li>\n<li>Arrays in C, C++<br \/>\n<strong><a href=\"https:\/\/www.geeksforgeeks.org\/arrays-in-c-cpp\/\">https:\/\/www.geeksforgeeks.org\/arrays-in-c-cpp\/<\/a><\/strong><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Lab content Math.h library introduction Type casting Floating point precision Slides:\u00a0Arrays Additional example: distance converter Tasks The task for this week is separated into two parts. First complete the first part and present your solution. Then improve your existing solution by solving the second part of the task and present the solution again. The base &hellip; <a href=\"https:\/\/blue.pri.ee\/ttu\/labs\/4-lab-arrays\/\" class=\"more-link\">Loe edasi <span class=\"screen-reader-text\">PR1EN5: Arrays<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[75,77],"tags":[],"class_list":["post-5378","post","type-post","status-publish","format-standard","hentry","category-labs","category-pr1_en"],"_links":{"self":[{"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/posts\/5378","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/comments?post=5378"}],"version-history":[{"count":15,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/posts\/5378\/revisions"}],"predecessor-version":[{"id":10774,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/posts\/5378\/revisions\/10774"}],"wp:attachment":[{"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/media?parent=5378"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/categories?post=5378"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/tags?post=5378"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}