{"id":6542,"date":"2024-09-01T00:01:22","date_gmt":"2024-09-01T07:01:22","guid":{"rendered":"https:\/\/c-for-dummies.com\/blog\/?p=6542"},"modified":"2024-09-08T11:45:14","modified_gmt":"2024-09-08T18:45:14","slug":"describing-complex-data","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=6542","title":{"rendered":"Describing Complex Data"},"content":{"rendered":"<h2>Difficulty: &#9733; &#9733; &#9734; &#9734;<\/h2>\n<p>I&#8217;ve written many C programming Lessons and Exercises that deal with matrixes. For most of them, such as <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=3685\">rotating a matrix<\/a>, I rely on uniform matrix sizes, like 5&#215;5 or 10&#215;10. This approach makes coding easier, but it doesn&#8217;t properly describe every type of matrix.<br \/>\n<!--more--><br \/>\nA matrix, or grid, contains rows and columns of data. Depending on what&#8217;s being described, the rows and columns can be different: 2&#215;4, 8&#215;16, 18&#215;5. These are all valid matrix sizes, often expressed in C as a two-dimensional array:<\/p>\n<p><code>alpha[2][4]<br \/>\nbeta[8][16]<br \/>\ngamma[18][5]<\/code><\/p>\n<p>Manipulating such an array involves brainwork, but things get dicey when passing these matrixes to a function. In my code, I often use a pointer as an argument. It&#8217;s easier to pass but still involves overhead when calculating row and column offsets.<\/p>\n<p>A larger problem is how to inform a function of a matrix&#8217;s dimensions. Other programming languages may offer a method to obtain row and column values in a matrix &mdash; but in C you must come up with another way to describe this complex data, which is the topic of this month&#8217;s Exercise.<\/p>\n<p>Your task is to output these two matrixes:<\/p>\n<p><code>int matrix_a[12] = {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;10, 20, 30, 40,<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;11, 21, 31, 41,<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;12, 22, 32, 42<br \/>\n};<br \/>\nint matrix_b[4] = {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;1, 2,<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;3, 4<br \/>\n};<\/code><\/p>\n<p>Each matrix is declared in the <em>main()<\/em> function, but as a single-dimension array. What&#8217;s desired is a matrix as shown in the format: 4&#215;3 and 2&#215;2. These dimensions are how the matrixes should be treated, which is important.<\/p>\n<p>In your solution you must code a function to output the matrixes as a grid. The matrix must be passed to the function as a single argument, a complex data type that describes the matrix&#8217;s dimensions and values.<\/p>\n<p>Here is output from my solution:<\/p>\n<p><code>Matrix&nbsp;A<br \/>\n&nbsp;&nbsp;10&nbsp;&nbsp;&nbsp;20&nbsp;&nbsp;&nbsp;30&nbsp;&nbsp;&nbsp;40&nbsp;<br \/>\n&nbsp;&nbsp;11&nbsp;&nbsp;&nbsp;21&nbsp;&nbsp;&nbsp;31&nbsp;&nbsp;&nbsp;41&nbsp;<br \/>\n&nbsp;&nbsp;12&nbsp;&nbsp;&nbsp;22&nbsp;&nbsp;&nbsp;32&nbsp;&nbsp;&nbsp;42&nbsp;<br \/>\nMatrix&nbsp;B<br \/>\n&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;2&nbsp;<br \/>\n&nbsp;&nbsp;&nbsp;3&nbsp;&nbsp;&nbsp;&nbsp;4&nbsp;<\/code><\/p>\n<p>I use two arguments for my version of <em>output()<\/em> function. The first contains the title string, such as &#8220;Matrix A&#8221; above. The second argument is the complex data type that describes the array, its contents and dimensions.<\/p>\n<p>Please try this exercise on your own before checking out <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=6553\">my solution<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Devise a way to describe a matrix, specifically one with non-uniform dimensions. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=6542\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-6542","post","type-post","status-publish","format-standard","hentry","category-exercise"],"_links":{"self":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6542","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6542"}],"version-history":[{"count":9,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6542\/revisions"}],"predecessor-version":[{"id":6577,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6542\/revisions\/6577"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6542"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6542"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6542"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}