{"id":6402,"date":"2021-10-27T15:43:59","date_gmt":"2021-10-27T13:43:59","guid":{"rendered":"https:\/\/blue.pri.ee\/ttu\/?p=6402"},"modified":"2025-11-06T22:11:09","modified_gmt":"2025-11-06T20:11:09","slug":"10-functions-2-and-pseudorandom-numbers","status":"publish","type":"post","link":"https:\/\/blue.pri.ee\/ttu\/labs\/10-functions-2-and-pseudorandom-numbers\/","title":{"rendered":"PR1EN10: Menu-program"},"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\/10-functions-2-and-pseudorandom-numbers\/#Theory_and_reminders\" >Theory and reminders<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/10-functions-2-and-pseudorandom-numbers\/#Characters_strings_and_output_functions\" >Characters, strings and output functions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/10-functions-2-and-pseudorandom-numbers\/#Passing_arrays_to_functions\" >Passing arrays to functions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/10-functions-2-and-pseudorandom-numbers\/#Swapping_two_values_in_an_array\" >Swapping two values in an array<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/10-functions-2-and-pseudorandom-numbers\/#Zero-initializing_an_array\" >Zero-initializing an array<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/10-functions-2-and-pseudorandom-numbers\/#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-7\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/10-functions-2-and-pseudorandom-numbers\/#Sample_program\" >Sample program<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/10-functions-2-and-pseudorandom-numbers\/#Task_description\" >Task description<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/10-functions-2-and-pseudorandom-numbers\/#General_requirements\" >General requirements<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/10-functions-2-and-pseudorandom-numbers\/#Lab_task_part_1_W10-1_Generating_and_displaying_of_the_matrix\" >Lab task part 1 [W10-1]: Generating and displaying of the matrix<\/a><\/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\/10-functions-2-and-pseudorandom-numbers\/#Lab_task_part_2_W10-2_Swapping_rows_and_columns\" >Lab task part 2 [W10-2]: Swapping rows and columns<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/10-functions-2-and-pseudorandom-numbers\/#Common_mistakes\" >Common mistakes<\/a><\/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\/10-functions-2-and-pseudorandom-numbers\/#Extra_task_1_W10-3_Deletion\" >Extra task 1 [W10-3]: Deletion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/10-functions-2-and-pseudorandom-numbers\/#Extra_task_2_W10-4_Addition\" >Extra task 2 [W10-4]: Addition<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/blue.pri.ee\/ttu\/labs\/10-functions-2-and-pseudorandom-numbers\/#Extra_task_3_W10-5_Transposing\" >Extra task 3 [W10-5]: Transposing<\/a><\/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\/10-functions-2-and-pseudorandom-numbers\/#After_this_class_you_should\" >After this 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\/10-functions-2-and-pseudorandom-numbers\/#Additional_content\" >Additional content<\/a><\/li><\/ul><\/nav><\/div>\n<h3><span class=\"ez-toc-section\" id=\"Theory_and_reminders\"><\/span>Theory and reminders<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4><span class=\"ez-toc-section\" id=\"Characters_strings_and_output_functions\"><\/span>Characters, strings and output functions<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>Even though we will deep-dive into strings in a few weeks, we will introduce a few properties today.<\/p>\n<p><strong>A strings<\/strong> is a sequence of characters. It can be a word or a sentence, but could also just a sequence of characters. Strings are between <strong>double quotes.<\/strong><\/p>\n<p>Examples:<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><span class=\"lang:default highlight:0 decode:true crayon-inline\">&#8220;a&#8221;<\/span><\/li>\n<li><span class=\"lang:default highlight:0 decode:true crayon-inline\">&#8220;Hello!&#8221;<\/span><\/li>\n<li><span class=\"lang:default highlight:0 decode:true crayon-inline\">&#8220;I do wish we could chat longer, but I&#8217;m having an old friend for dinner.&#8221;<\/span><\/li>\n<li><span class=\"lang:default highlight:0 decode:true crayon-inline\">&#8220;lFRD=)m+0FDj2&#8221;<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Characters are written in between single quotes. A string is composed of such characters.<\/p>\n<p>NB! Symbols starting with a backslash are called escape sequences and they are also coded (and stored) as a single character in the computer memory (e.g. \u00a0<span class=\"lang:default highlight:0 decode:true crayon-inline\">\\n<\/span>\u00a0 is really a single character, it takes up just one byte).<\/p>\n<p>Examples:<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><span class=\"lang:default highlight:0 decode:true crayon-inline\">&#8216;a&#8217;<\/span><\/li>\n<li><span class=\"lang:default highlight:0 decode:true crayon-inline\">&#8216;y&#8217;<\/span><\/li>\n<li><span class=\"lang:default highlight:0 decode:true crayon-inline\">&#8216;\\n&#8217;<\/span><\/li>\n<li><span class=\"lang:default highlight:0 decode:true crayon-inline\">&#8216;\\t&#8217;<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Notice, that <span class=\"lang:c highlight:0 decode:true crayon-inline \">&#8216;a&#8217;<\/span>\u00a0 and <span class=\"lang:c highlight:0 decode:true crayon-inline \">&#8220;a&#8221;<\/span>\u00a0 were both shown in the example and the are different. One is a string, the other is a character.<\/p>\n<p>Now lets take a look at some functions that are used for printing strings and characters.<\/p>\n<p><span class=\"lang:default highlight:0 decode:true crayon-inline\">printf()<\/span>\u00a0 \u00a0&#8211; print formatted. This is the most complicated output function that we&#8217;ve looked at so far. We can use it to print text, format it and also output the contents of variables. Newlines must be manually added.<\/p>\n<p>Example: <span class=\"lang:default decode:true crayon-inline\">printf(&#8220;Hello, %s!\\n&#8221;, name);<\/span><\/p>\n<p><span class=\"lang:default highlight:0 decode:true crayon-inline\">puts()<\/span>\u00a0 &#8211; put string. This is a simple output function used for printing text on separate lines. It does not support formatting and printing contents of variables. It will print a newline in the end of the string.<\/p>\n<p>Example: <span class=\"lang:default decode:true crayon-inline\">puts(&#8220;Hello, user!&#8221;);<\/span><\/p>\n<p><span class=\"lang:default highlight:0 decode:true crayon-inline\">putchar()<\/span>\u00a0 \u00a0&#8211; put character. This is the simplest output function out of them. It only allows printing of a single character. It is often used for printing single newlines or other special characters.<\/p>\n<p>Example: <span class=\"lang:default decode:true crayon-inline\">putchar(&#8216;\\n&#8217;);<\/span><\/p>\n<h4><span class=\"ez-toc-section\" id=\"Passing_arrays_to_functions\"><\/span>Passing arrays to functions<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>When passing arrays to functions, we are actually passing a reference to the location of the array. This means we can modify\u00a0 the array members in all functions without using a return statement.<\/p>\n<p>In C, you typically need to also pass the size of the array. This is due to the fact that it will not be possible to calculate the size after it has been passed to a function. An exception would be strings, which we&#8217;ll discuss further later.<\/p>\n<p>Some more tricks and specifics<\/p>\n<ul>\n<li>If you want to pass\u00a0<strong>the whole array<\/strong>, regardless of the number of dimensions, we only specify the name of the array <span class=\"lang:default decode:true crayon-inline\">Func(numbers);<\/span><\/li>\n<li>If you wish to pass\u00a0<strong>only a single value<\/strong> from a 1-dimensional array <span class=\"lang:default decode:true crayon-inline\">int numbers[N];<\/span> , we will specify the index of that member <span class=\"lang:default decode:true crayon-inline\">Func(numbers[2]);<\/span> . In the function we will use it as a single integer <span class=\"lang:default decode:true crayon-inline\">Func(int val);<\/span><\/li>\n<li>If you wish to pass\u00a0<strong>the beginning of a row<\/strong> from a 2-dimensional array <span class=\"lang:default decode:true crayon-inline\">int numbers[N][M];<\/span> , we will specify the index of that row and the length of it <span class=\"lang:default decode:true crayon-inline\">Func(numbers[2], M);<\/span> . In the function we will use it as a 1-dimensional array <span class=\"lang:default decode:true crayon-inline\">Func(int numbs[], int n);<\/span><\/li>\n<li>If you wish to pass\u00a0<strong>only a single value<\/strong> from a 2-dimensional array <span class=\"lang:default decode:true crayon-inline\">int numbers[N][M];<\/span> , we will specify both indexes\u00a0 <span class=\"lang:default decode:true crayon-inline\">Func(numbers[2][1]);<\/span> . In the function we will use it as a single integer <span class=\"lang:default decode:true crayon-inline \">Func(int val);<\/span><\/li>\n<\/ul>\n<h4><span class=\"ez-toc-section\" id=\"Swapping_two_values_in_an_array\"><\/span>Swapping two values in an array<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>To swap to values, you can use a method we learned during bubble sort lesson. For this, you will need a temporary variable.<\/p>\n<pre class=\"toolbar:2 lang:default decode:true\">int temp = value[idx];\r\nvalue[i] = value[idx + 1];\r\nvalue[idx + 1] = temp;<\/pre>\n<p>Note: to apply this method for a swapping of rows or columns in the lab task, you only need a single variable.<\/p>\n<p>Using an array can be beneficial if you have support for parallel processing &#8211; e.g. you can copy over multiple values at the same time instead of sequentially. This is a common approach for graphics card, which are optimized for highly parallelized workloads. This is also a very common for any kind of AI based solutions, that are typically based off matrix calculation, that you will learn in linear algebra.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"Zero-initializing_an_array\"><\/span>Zero-initializing an array<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>To zero-initialize the whole array, we put a zero constant in curly braces.<\/p>\n<pre class=\"toolbar:2 lang:default decode:true\">int vector[LEN] = {0};<\/pre>\n<p>If it is a 2-dimensional array, need two sets of curly braces.<\/p>\n<pre class=\"toolbar:2 lang:default decode:true \">int matrix[ROWS][COLS] = {{0}};<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Tasks\"><\/span>Tasks<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>In this class, you will create a menu based program, that will work until the user desires to exit. The program handles some basic matrix manipulation.\u00a0 Pay attention to edge cases during the task &#8211; i.e. what happens if the user wishes to manipulate a matrix, that does not yet exist.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"Sample_program\"><\/span>Sample program<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>You are given a sample of the program you that you need to mimic for this lab task. It is given as a compiled binary &#8211; you can run and test it to take a look at what the final product should look like. In the end, your program should work similarly.<\/p>\n<p>Both versions of the sample program are compiled for x86-64 architecture. They are guaranteed to work on the lab computers, but should also work on most of your personal computers. There can be issues with ARM processors without using x86-64 emulation.<\/p>\n<ul>\n<li><strong><a href=\"http:\/\/blue.pri.ee\/ttu\/files\/Prog1\/10_lab_switch_linux\">Sample program (Linux)<\/a><\/strong><\/li>\n<li><strong><a href=\"http:\/\/blue.pri.ee\/ttu\/files\/Prog1\/10_lab_switch_win.exe\">Sample program (Windows)<\/a><\/strong><\/li>\n<\/ul>\n<p>NB! On Linux you must give the permission to execute it manually (this is a security requirement). Changing the permission is a one-time task.<\/p>\n<pre class=\"toolbar:2 lang:default highlight:0 decode:true\">chmod u+x 10_lab_switch_linux<\/pre>\n<p>This will add the execute permission for the user.<\/p>\n<ul>\n<li>chmod &#8211; change mode<\/li>\n<li>u &#8211; user<\/li>\n<li>x &#8211; execute<\/li>\n<\/ul>\n<p>After this you can run the program as usual ( <span class=\"lang:default highlight:0 decode:true crayon-inline\">.\/program_name<\/span>)<\/p>\n<h4><span class=\"ez-toc-section\" id=\"Task_description\"><\/span>Task description<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>The lab task is separated into two separately graded parts, which can be continued by adding extra tasks.<\/p>\n<p>The program should work until the user chooses to exit. This may require you to add additional checks for the state of the matrix.<\/p>\n<p>The maximum size of the matrix in memory is defined using macros <span class=\"lang:default highlight:0 decode:true crayon-inline\">LIMIT_ROWS<\/span> and <span class=\"lang:default highlight:0 decode:true crayon-inline\">LIMIT_COLS<\/span> , which define the maximum row and column counts. Make sure not to mix them up!<\/p>\n<p>Since the user can choose to use less than the maximum matrix size, part of the matrix may be left unused. To account for this, all functions should keep track of how large of an area of the matrix is in use. For this, you will see <span class=\"lang:default highlight:0 decode:true crayon-inline\">int rows<\/span>\u00a0 and <span class=\"lang:default highlight:0 decode:true crayon-inline\">int cols<\/span>\u00a0 being used in some functions for the amount of rows and cols currently active.<\/p>\n<p><strong>Download the starter code: <a href=\"https:\/\/blue.pri.ee\/ttu\/files\/iax0583\/aluskoodid\/10_switch_basecode.c\">https:\/\/blue.pri.ee\/ttu\/files\/iax0583\/aluskoodid\/10_switch_basecode.c<\/a><\/strong><\/p>\n<h4><span class=\"ez-toc-section\" id=\"General_requirements\"><\/span>General requirements<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>These requirements apply regardless of which part of the program you are presenting.<\/p>\n<ul>\n<li>Your solution must mimic the sample program as close as possible<\/li>\n<li>The solution must be built on the starter code\n<ul>\n<li>You are allowed to modify the starter code within reason. E.g. it might be beneficial to reorder some statements in the main function or add another parameter to the function <span class=\"lang:default highlight:0 decode:true crayon-inline\">GetIntInRange()<\/span> . For any other modifications, think hard if they are necessary or useful!<\/li>\n<li>Starter code already has 2 functions made for you. Use them as needed in the parts that you will code on your own!<\/li>\n<li>Starter code also has the prototypes of the first two functions that you need to create during the first part of the task.<\/li>\n<\/ul>\n<\/li>\n<li>The application should work with a matrix that has different number of rows and columns, i.e. is not a square matrix.<\/li>\n<li>All the numbers in the matrix must be randomly generated and be in range of 0 &#8211; 99.<\/li>\n<li>All actions must be repeatable without exiting the program.<\/li>\n<li>All of the processing code for the menu actions must be created as functions\n<ul>\n<li>You are free to print out helping texts and prompts in the <span class=\"lang:c highlight:0 decode:true  crayon-inline \">switch()<\/span>\u00a0 itself, as well as accept returned values from functions. If necessary, you can also add some <span class=\"lang:c highlight:0 decode:true  crayon-inline \">if<\/span>\u00a0 statements.<\/li>\n<li>Do not declare any variables in the switch statement!<\/li>\n<li>You are not allowed to add any new loops to the <span class=\"lang:c highlight:0 decode:true  crayon-inline \">main()<\/span>\u00a0 function!<\/li>\n<\/ul>\n<\/li>\n<li>The program must run until the user chooses to exit. All prompts for the user must be clear. The program must work as a whole, as you add new parts to it.<\/li>\n<\/ul>\n<h4><span class=\"ez-toc-section\" id=\"Lab_task_part_1_W10-1_Generating_and_displaying_of_the_matrix\"><\/span>Lab task part 1 [W10-1]: Generating and displaying of the matrix<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>In the first part, we&#8217;ll complete the generation and displaying of the matrix. You will also be practicing nesting different loop types!<\/p>\n<p><strong>Requirements<\/strong><\/p>\n<ul>\n<li>Use can generate an <strong>n * m<\/strong> matrix.\n<ul>\n<li>Matrix will be populated with randomly generated numbers (0 &#8211; 99)<\/li>\n<li>Values <strong>n<\/strong> and <strong>m<\/strong> are entered by the user. If necessary, create limits for user input.<\/li>\n<li>You are only allowed to use <span class=\"lang:default highlight:0 decode:true crayon-inline\">do while()<\/span>\u00a0 loops in\u00a0<span class=\"lang:default highlight:0 decode:true crayon-inline\">GenerateMatrix()<\/span> function.<\/li>\n<li>Reminder! C functions are simple and only do one thing at a time (and do it well)! Function \u00a0<span class=\"lang:default highlight:0 decode:true crayon-inline\">GenerateMatrix()<\/span> <strong>is not allowed to handle user input!<\/strong><\/li>\n<\/ul>\n<\/li>\n<li>User can display a matrix\n<ul>\n<li>You are only allowed to use\u00a0 <span class=\"lang:default highlight:0 decode:true crayon-inline\">while()<\/span>\u00a0 loops in <span class=\"lang:default highlight:0 decode:true crayon-inline\">DisplayMatrix()<\/span> function.<\/li>\n<li>Matrix must be properly aligned.<\/li>\n<\/ul>\n<\/li>\n<li>User can exit the program<\/li>\n<\/ul>\n<h4><span class=\"ez-toc-section\" id=\"Lab_task_part_2_W10-2_Swapping_rows_and_columns\"><\/span>Lab task part 2 [W10-2]: Swapping rows and columns<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>In the second part, we will create functions for swapping rows and columns.<\/p>\n<p><strong>Requirements:<\/strong><\/p>\n<ul>\n<li>User must be able to swap two rows.\n<ul>\n<li>You are only allowed to use <span class=\"lang:default highlight:0 decode:true crayon-inline\">for()<\/span>\u00a0 loops in the swapping function.<\/li>\n<\/ul>\n<\/li>\n<li>User must be able to swap two columns.<\/li>\n<\/ul>\n<h4><span class=\"ez-toc-section\" id=\"Common_mistakes\"><\/span>Common mistakes<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<ul>\n<li>Copy-pasting, also known as repetitive code. Mostly this will happen in the input part (e.g. number of rows, columns etc.)<\/li>\n<li>Off by one issues. As a reminder, first row index is 0.<\/li>\n<li>Magical numbers<\/li>\n<li>Allowing matrix operations before having a matrix. You cannot display a matrix that has not yet been generated!<\/li>\n<li>Wrong loop types (part 1 and 2 have fixed loop types that you can use!).<\/li>\n<li>Mixing up row and column counts. Try the following\n<ul>\n<li>generate a 3 x 5 matrix, swap rows 1 and 3<\/li>\n<\/ul>\n<ul>\n<li>generate a 5 x 3 matrix, swap columns 1 and 3<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4><span class=\"ez-toc-section\" id=\"Extra_task_1_W10-3_Deletion\"><\/span>Extra task 1 [W10-3]: Deletion<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>Add additional features to your program<\/p>\n<ul>\n<li>User can delete a row that they desire.<\/li>\n<li>User can delete a column that they desire.<\/li>\n<li>After deleting a row, all rows following it will rise higher by 1. Similarly after deleting a column, all columns following it will move the the left by 1. The size of the matrix will shrink.<\/li>\n<li>Add the required functionality to the menu.<\/li>\n<\/ul>\n<h4><span class=\"ez-toc-section\" id=\"Extra_task_2_W10-4_Addition\"><\/span>Extra task 2 [W10-4]: Addition<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>Add additional features to your program<\/p>\n<ul>\n<li>User can add a new row to the desired location.<\/li>\n<li>User can add a new column to the desired location.<\/li>\n<li>All elements for the added row \/ column will be generated randomly.<\/li>\n<li>Any rows or columns after the desired location will move forward by 1. The size of the matrix increases.<\/li>\n<li>Add the required functionality to the menu.<\/li>\n<\/ul>\n<h4><span class=\"ez-toc-section\" id=\"Extra_task_3_W10-5_Transposing\"><\/span>Extra task 3 [W10-5]: Transposing<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>Add additional features to your program<\/p>\n<ul>\n<li>User can transpose the matrix.<\/li>\n<li>Add the required functionality to the menu.<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"After_this_class_you_should\"><\/span><span id=\"Parast_seda_tundi_peaksid\" class=\"ez-toc-section\"><\/span><strong>After this class, you should<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>Be able to create infinitely running menu-programs.<\/li>\n<li>Know a few additional functions for text output.<\/li>\n<li>Know the difference between a character and a string in C code<\/li>\n<li>Be able to pass to a function\n<ul>\n<li>a whole matrix<\/li>\n<li>one row from a matrix<\/li>\n<li>one element from a matrix<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Additional_content\"><\/span><span id=\"Taiendav_materjal\" class=\"ez-toc-section\"><\/span><strong>Additional content<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>Menu-Driven program using Switch-case in C<br \/>\n<a href=\"https:\/\/www.geeksforgeeks.org\/menu-driven-program-using-switch-case-c\/\">https:\/\/www.geeksforgeeks.org\/menu-driven-program-using-switch-case-c\/<\/a><\/li>\n<li>Escape sequences in C<br \/>\n<a href=\"https:\/\/en.wikipedia.org\/wiki\/Escape_sequences_in_C\">https:\/\/en.wikipedia.org\/wiki\/Escape_sequences_in_C<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Theory and reminders Characters, strings and output functions Even though we will deep-dive into strings in a few weeks, we will introduce a few properties today. A strings is a sequence of characters. It can be a word or a sentence, but could also just a sequence of characters. Strings are between double quotes. Examples: &hellip; <a href=\"https:\/\/blue.pri.ee\/ttu\/labs\/10-functions-2-and-pseudorandom-numbers\/\" class=\"more-link\">Loe edasi <span class=\"screen-reader-text\">PR1EN10: Menu-program<\/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-6402","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\/6402","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=6402"}],"version-history":[{"count":9,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/posts\/6402\/revisions"}],"predecessor-version":[{"id":10877,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/posts\/6402\/revisions\/10877"}],"wp:attachment":[{"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/media?parent=6402"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/categories?post=6402"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/tags?post=6402"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}