{"id":5031,"date":"2021-11-01T00:01:14","date_gmt":"2021-11-01T07:01:14","guid":{"rendered":"https:\/\/c-for-dummies.com\/blog\/?p=5031"},"modified":"2021-11-09T07:07:25","modified_gmt":"2021-11-09T15:07:25","slug":"the-power-grid","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=5031","title":{"rendered":"The Power Grid"},"content":{"rendered":"<h2>Difficulty: Easy<\/h2>\n<p>I enjoy programming tables, rows and columns. The standard technique is to use a nested loop. In fact, when teaching nested loops, outputting a table is par for the course.<br \/>\n<!--more--><br \/>\nWhile creating a nested loop isn&#8217;t difficult, it does take time to get the table formatting just so. I often dither on whether to add a header row, and set other various facets of table-making that can make the output more interesting and useful.<\/p>\n<p>For this month&#8217;s Exercise, your challenge is to output a table of powers. It&#8217;s a grid with values zero through five across each row and values zero through six going down each column. For each cell in the table, the power of row<sup>column<\/sup> is calculated:<\/p>\n<pre class=\"screen\">\r\n0^1 =    0\t0^2 =    0\t0^3 =    0\t0^4 =    0\t0^5 =    0\t\r\n1^1 =    1\t1^2 =    1\t1^3 =    1\t1^4 =    1\t1^5 =    1\t\r\n2^1 =    2\t2^2 =    4\t2^3 =    8\t2^4 =   16\t2^5 =   32\t\r\n3^1 =    3\t3^2 =    9\t3^3 =   27\t3^4 =   81\t3^5 =  243\t\r\n4^1 =    4\t4^2 =   16\t4^3 =   64\t4^4 =  256\t4^5 = 1024\t\r\n5^1 =    5\t5^2 =   25\t5^3 =  125\t5^4 =  625\t5^5 = 3125\t\r\n6^1 =    6\t6^2 =   36\t6^3 =  216\t6^4 = 1296\t6^5 = 7776<\/pre>\n<p>In the table above, which is output from my solution (and without any header row), I use the caret (^) to indicate power. The caret isn&#8217;t the power operator in the C language, though it&#8217;s used as such in other languages. For brevity&#8217;s sake I chose to use it in this table. No, in C you use <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=1968\">the <em>pow()<\/em> function<\/a> to calculate exponents. (Hint.)<\/p>\n<p>This task isn&#8217;t as much about generating powers or coding a nested loop as it is to get the table to output properly, as shown above. This reason is why the table is limited in size. If not, the exponential values increase rapidly in width, making a neat table more difficult on a text screen.<\/p>\n<p>Please try this Exercise on your own before you peek at <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=5045\">my solution<\/a>, which I&#8217;ll post in a week.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Tables are fun to program. At least I think so. Maybe a bit of math can raise the bar? <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=5031\">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-5031","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\/5031","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=5031"}],"version-history":[{"count":6,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/5031\/revisions"}],"predecessor-version":[{"id":5064,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/5031\/revisions\/5064"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5031"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5031"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5031"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}