bsc

Comprehensive codebase and cou...
Log | Files | Refs | README | LICENSE

commit 02772235cb42ba8ef61ba006719b57010456d9a4
parent e110a7d8010934efd936a11379dae4b99bbe80ee
Author: Amit Dutta <amitdutta4255@gmail.com>
Date:   Mon, 10 Nov 2025 19:04:05 +0530

update -10112025 _P53 -rewritten source code (rewritten logics for pattern 2 to 7)

Diffstat:
Mdocs/index.html | 140++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
Mtuition-c/P053.c | 140++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 272 insertions(+), 8 deletions(-)

diff --git a/docs/index.html b/docs/index.html @@ -8023,6 +8023,7 @@ int main() { int i, j, temp; + printf(&quot;\n\nPattern 1 : \n\n&quot;); /* 9 9 9 9 9 7 7 7 7 7 @@ -8030,10 +8031,141 @@ int main() 3 3 3 3 3 1 1 1 1 1 */ - temp = 9; - for(i = 1; i &lt;= 5; i++) { - - } + temp = 9; + for (i = 1; i &lt;= 5; i++) + { + for (j = 1; j &lt;= 5; j++) + { + printf(&quot;%d &quot;, temp); + } + printf(&quot;\n&quot;); + temp -= 2; + } + + // Another method print above pattern + printf(&quot;\n\nPattern 1 : \n\n&quot;); + for (i = 9; i &gt;= 1; i -= 2) + { + for (j = 1; j &lt;= 5; j++) + { + printf(&quot;%d &quot;, i); + } + printf(&quot;\n&quot;); + } + + printf(&quot;\n\nPattern 2 : \n\n&quot;); + /* + 1 2 3 4 5 + 1 2 3 4 5 + 1 2 3 4 5 + */ + for (i = 1; i &lt;= 3; i++) + { + for (j = 1; j &lt;= 5; j++) + { + printf(&quot;%d &quot;, j); + } + printf(&quot;\n&quot;); + } + + printf(&quot;\n\nPattern 3 : \n\n&quot;); + /* + 5 4 3 2 1 + 5 4 3 2 1 + */ + for (i = 1; i &lt;= 2; i++) + { + for (j = 5; j &gt;= 1; j--) + { + printf(&quot;%d &quot;, j); + } + printf(&quot;\n&quot;); + } + + printf(&quot;\n\nPattern 4 : \n\n&quot;); + /* + 1 2 3 4 + 5 6 7 8 + 9 10 11 12 + */ + temp = 1; + for (i = 1; i &lt;= 3; i++) + { + for (j = 1; j &lt;= 4; j++) + { + printf(&quot;%d &quot;, temp); + temp++; + } + printf(&quot;\n&quot;); + } + + printf(&quot;\n\nPattern 5 : \n\n&quot;); + /* + 1 2 3 4 + 4 8 12 16 + 1 2 3 4 + 4 8 12 16 + 1 2 3 4 + */ + for (i = 1; i &lt;= 5; i++) + { + for (j = 1; j &lt;= 4; j++) + { + if (i % 2 == 0) + printf(&quot;%d &quot;, j * 4); + else + printf(&quot;%d &quot;, j); + } + printf(&quot;\n&quot;); + } + + printf(&quot;\n\nPattern 6 : \n\n&quot;); + /* + 1 + 2 4 + 3 5 7 + 6 8 10 12 + 9 11 13 15 17 + */ + int odd = 1, even = 2; + for (i = 1; i &lt;= 5; i++) + { + for (j = 1; j &lt;= i; j++) + { + if (i % 2 == 0) + { + printf(&quot;%d &quot;, even); + even += 2; + } + else + { + printf(&quot;%d &quot;, odd); + odd += 2; + } + } + printf(&quot;\n&quot;); + } + + printf(&quot;\n\nPattern 7 : \n\n&quot;); + /* + 1 2 3 4 5 + 6 7 8 9 + 10 11 12 + 13 14 + 15 + */ + temp = 1; + for (i = 5; i &gt;= 1; i--) + { + for (j = 1; j &lt;= i; j++) + { + printf(&quot;%d &quot;, temp); + temp++; + } + printf(&quot;\n&quot;); + } + + return 0; }</code></pre> </div> </li> diff --git a/tuition-c/P053.c b/tuition-c/P053.c @@ -11,6 +11,7 @@ int main() { int i, j, temp; + printf("\n\nPattern 1 : \n\n"); /* 9 9 9 9 9 7 7 7 7 7 @@ -18,8 +19,139 @@ int main() 3 3 3 3 3 1 1 1 1 1 */ - temp = 9; - for(i = 1; i <= 5; i++) { - - } + temp = 9; + for (i = 1; i <= 5; i++) + { + for (j = 1; j <= 5; j++) + { + printf("%d ", temp); + } + printf("\n"); + temp -= 2; + } + + // Another method print above pattern + printf("\n\nPattern 1 : \n\n"); + for (i = 9; i >= 1; i -= 2) + { + for (j = 1; j <= 5; j++) + { + printf("%d ", i); + } + printf("\n"); + } + + printf("\n\nPattern 2 : \n\n"); + /* + 1 2 3 4 5 + 1 2 3 4 5 + 1 2 3 4 5 + */ + for (i = 1; i <= 3; i++) + { + for (j = 1; j <= 5; j++) + { + printf("%d ", j); + } + printf("\n"); + } + + printf("\n\nPattern 3 : \n\n"); + /* + 5 4 3 2 1 + 5 4 3 2 1 + */ + for (i = 1; i <= 2; i++) + { + for (j = 5; j >= 1; j--) + { + printf("%d ", j); + } + printf("\n"); + } + + printf("\n\nPattern 4 : \n\n"); + /* + 1 2 3 4 + 5 6 7 8 + 9 10 11 12 + */ + temp = 1; + for (i = 1; i <= 3; i++) + { + for (j = 1; j <= 4; j++) + { + printf("%d ", temp); + temp++; + } + printf("\n"); + } + + printf("\n\nPattern 5 : \n\n"); + /* + 1 2 3 4 + 4 8 12 16 + 1 2 3 4 + 4 8 12 16 + 1 2 3 4 + */ + for (i = 1; i <= 5; i++) + { + for (j = 1; j <= 4; j++) + { + if (i % 2 == 0) + printf("%d ", j * 4); + else + printf("%d ", j); + } + printf("\n"); + } + + printf("\n\nPattern 6 : \n\n"); + /* + 1 + 2 4 + 3 5 7 + 6 8 10 12 + 9 11 13 15 17 + */ + int odd = 1, even = 2; + for (i = 1; i <= 5; i++) + { + for (j = 1; j <= i; j++) + { + if (i % 2 == 0) + { + printf("%d ", even); + even += 2; + } + else + { + printf("%d ", odd); + odd += 2; + } + } + printf("\n"); + } + + printf("\n\nPattern 7 : \n\n"); + /* + 1 2 3 4 5 + 6 7 8 9 + 10 11 12 + 13 14 + 15 + */ + temp = 1; + for (i = 5; i >= 1; i--) + { + for (j = 1; j <= i; j++) + { + printf("%d ", temp); + temp++; + } + printf("\n"); + } + + return 0; } \ No newline at end of file
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror