logo

Star Patterns-Programm in C

In diesem Thema lernen wir, wie man die Muster mithilfe der C-Sprache erstellt. Wir erstellen die Muster, indem wir entweder ein „*“-Sternzeichen oder ein anderes Zeichen verwenden. Wir erstellen verschiedene Muster oder eine geometrische Form wie Dreieck, Quadrat usw.

Wir werden die folgenden Muster behandeln. Sie können den Code jedes unten angegebenen Musters anzeigen, indem Sie auf das Muster klicken.

Star-Programm in C Star-Programm in C Star-Programm in C Star-Programm in C Star-Programm in C Star-Programm in C Star-Programm in C Star-Programm in C Star-Programm in C Star-Programm in C Star-Programm in C Star-Programm in C Star-Programm in C Star-Programm in C Star-Programm in C Star-Programm in C Star-Programm in C Star-Programm in C Star-Programm in C Star-Programm in C Star-Programm in C Star-Programm in C Star-Programm in C Star-Programm in C Star-Programm in C

Quadratisches Sternmuster

Der Code zum Erstellen des quadratischen Sternmusters ist unten angegeben:

 #include int main() { int n; printf(&apos;Enter the number of rows&apos;); scanf(&apos;%d&apos;,&amp;n); for(int i=0;i<n;i++) { for(int j="0;j&lt;n;j++)" printf('*'); } printf('
'); return 0; < pre> <p> <strong>Output</strong> </p> <img src="//techcodeview.com/img/c-tutorial/66/star-patterns-program-c-26.webp" alt="Star Program in C"> <h2 id="Hollow-Square-Star">Hollow Square Star Pattern</h2> <p>Now, we create the hollow square star pattern. The source code for this pattern is given below:</p> <pre> int main() { int n; printf(&apos;Enter the number of rows&apos;); scanf(&apos;%d&apos;,&amp;n); for(int i=1;i<=n;i++) { for(int j="1;j&lt;=n;j++)" if(i="=1" ||i="=n||j==1||j==n)" printf('*'); } else printf(' '); printf('
'); return 0; < pre> <p> <strong>Output</strong> </p> <img src="//techcodeview.com/img/c-tutorial/66/star-patterns-program-c-27.webp" alt="Star Program in C"> <h2 id="Hollow-Square-Pattern">Hollow Square Pattern with Diagonal</h2> <p>The code for the hollow square star pattern is given below:</p> <pre> #include int main() { int n; printf(&apos;Enter the number of rows&apos;); scanf(&apos;%d&apos;,&amp;n); for(int i=1;i<=n;i++) { for(int j="1;j&lt;=n;j++)" if(i="=1" ||i="=n||j==1||j==n-i+1||i==j||j==n)" printf('*'); } else printf(' '); printf('
'); return 0; < pre> <p> <strong>Output</strong> </p> <img src="//techcodeview.com/img/c-tutorial/66/star-patterns-program-c-28.webp" alt="Star Program in C"> <h2 id="Rhombus-Star">Rhombus Star Pattern</h2> <p>The code for the rhombus star pattern is given below:</p> <pre> #include int main() { int n; printf(&apos;Enter the number of rows&apos;); scanf(&apos;%d&apos;,&amp;n); for(int i=n;i&gt;=1;i--) { for(int j=1;j<=i-1;j++) { printf(' '); } for(int k="1;k&lt;=n;k++)" printf('*'); printf('
'); return 0; < pre> <p> <strong>Output</strong> </p> <img src="//techcodeview.com/img/c-tutorial/66/star-patterns-program-c-29.webp" alt="Star Program in C"> <h2 id="Hollow-Rhombus-Star">Hollow Rhombus Star Pattern</h2> <p>The code for the hollow rhombus star pattern is given below:</p> <pre> #include int main() { int n; printf(&apos;Enter the number of rows&apos;); scanf(&apos;%d&apos;,&amp;n); for(int i=n;i&gt;=1;i--) { for(int j=1;j<=i-1;j++) { printf(' '); } for(int k="1;k&lt;=n;k++)" printf('*'); else printf('
'); return 0; < pre> <p> <strong>Output</strong> </p> <img src="//techcodeview.com/img/c-tutorial/66/star-patterns-program-c-30.webp" alt="Star Program in C"> <h2 id="Mirrored-Rhombus-Star">Mirrored Rhombus Star Pattern</h2> <p>The code for the mirrored rhombus star pattern is given below:</p> <pre> #include int main() { int n; printf(&apos;Enter the number of rows&apos;); scanf(&apos;%d&apos;,&amp;n); for(int i=1;i<=n;i++) { for(int j="1;j" <i;j++) printf(' '); } k="1;k&lt;=n;k++)" printf('*'); printf('
'); return 0; < pre> <p> <strong>Output</strong> </p> <img src="//techcodeview.com/img/c-tutorial/66/star-patterns-program-c-31.webp" alt="Star Program in C"> <h2 id="Hollow-Mirrored-Rhombus-Star">Hollow Mirrored Rhombus Star Pattern</h2> <p>The code for the hollow mirrored rhombus star pattern is given below:</p> <pre> #include int main() { int n; printf(&apos;Enter the number of rows&apos;); scanf(&apos;%d&apos;,&amp;n); for(int i=1;i<=n;i++) { for(int j="1;j" <i;j++) printf(' '); } k="1;k&lt;=n;k++)" printf('
'); return 0; < pre> <p> <strong>Output</strong> </p> <img src="//techcodeview.com/img/c-tutorial/66/star-patterns-program-c-32.webp" alt="Star Program in C"> <h2 id="Right-Triangle-Star">Right Triangle Star Pattern</h2> <p>The code for the right triangle star pattern is given below:</p> <pre> #include int main() { int n; printf(&apos;Enter the number of rows&apos;); scanf(&apos;%d&apos;,&amp;n); for(int i=1;i<=n;i++) { for(int j="1;j&lt;=i;j++)" printf('* '); } printf('
'); return 0; < pre> <p> <strong>Output</strong> </p> <img src="//techcodeview.com/img/c-tutorial/66/star-patterns-program-c-33.webp" alt="Star Program in C"> <h2 id="Hollow-Right-Triangle-Star">Hollow Right Triangle Star Pattern</h2> <p>The code for the hollow right triangle star pattern is given below:</p> <pre> #include int main() { int n; printf(&apos;Enter the number of rows&apos;); scanf(&apos;%d&apos;,&amp;n); for(int i=1;i<=n;i++) { for(int j="1;j&lt;=i;j++)" if(j="=1||" i="=j" || ) printf('*'); } else printf(' '); printf('
'); return 0; < pre> <p> <strong>Output</strong> </p> <img src="//techcodeview.com/img/c-tutorial/66/star-patterns-program-c-34.webp" alt="Star Program in C"> <h2 id="Mirrored-Right-Triangle-Star">Mirrored Right Triangle Star Pattern</h2> <p>The code for the mirrored right triangle star pattern is given below:</p> <pre> #include int main() { int n,m=1; printf(&apos;Enter the number of rows&apos;); scanf(&apos;%d&apos;,&amp;n); for(int i=n;i&gt;=1;i--) { for(int j=1;j<=i-1;j++) { printf(' '); } for(int k="1;k&lt;=m;k++)" printf('*'); printf('
'); m++; return 0; < pre> <p> <strong>Output</strong> </p> <img src="//techcodeview.com/img/c-tutorial/66/star-patterns-program-c-35.webp" alt="Star Program in C"> <h2 id="Hollow-Mirrored-Right-Triangle-Star">Hollow Mirrored Right Triangle Star Pattern</h2> <p>The code for the hollow mirrored right triangle star pattern is given below:</p> <pre> #include int main() { int n,m=1; printf(&apos;Enter the number of rows&apos;); scanf(&apos;%d&apos;,&amp;n); for(int i=n;i&gt;=1;i--) { for(int j=1;j<=i-1;j++) { printf(' '); } for(int k="1;k&lt;=m;k++)" m="=n)" printf('*'); else printf('
'); m++; return 0; < pre> <p> <strong>Output</strong> </p> <img src="//techcodeview.com/img/c-tutorial/66/star-patterns-program-c-36.webp" alt="Star Program in C"> <h2 id="Inverted-Right-Triangle-Star">Inverted Right Triangle Star Pattern</h2> <p>The code for the inverted right triangle star pattern is given below:</p> <pre> #include int main() { int n,m=1; printf(&apos;Enter the number of rows&apos;); scanf(&apos;%d&apos;,&amp;n); for(int i=n;i&gt;=1;i--) { for(int j=1;j<=i;j++) { printf('*'); } printf('
'); return 0; < pre> <p> <strong>Output</strong> </p> <img src="//techcodeview.com/img/c-tutorial/66/star-patterns-program-c-37.webp" alt="Star Program in C"> <h2 id="Hollow-Inverted-Right-Triangle-Star">Hollow Inverted Right Triangle Star Pattern</h2> <p>The code for the hollow inverted right triangle star pattern is given below:</p> <pre> #include int main() { int n,m=1; printf(&apos;Enter the number of rows&apos;); scanf(&apos;%d&apos;,&amp;n); for(int i=n;i&gt;=1;i--) { for(int j=1;j<=i;j++) i="=n)" printf('*'); else printf(' '); printf('
'); } return 0; < pre> <p> <strong>Output</strong> </p> <img src="//techcodeview.com/img/c-tutorial/66/star-patterns-program-c-38.webp" alt="Star Program in C"> <h2 id="Inverted-Mirrored-Right-Triangle-Star">Inverted Mirrored Right Triangle Star Pattern</h2> <p>The code for the inverted mirrored right triangle star pattern is given below:</p> <pre> #include int main() { int n,m; printf(&apos;Enter the number of rows&apos;); scanf(&apos;%d&apos;,&amp;n); m=n; for(int i=1;i<=n;i++) { for(int j="1;j" <i;j++) printf(' '); } k="1;k&lt;=m;k++)" printf('*'); m--; printf('
'); return 0; < pre> <p> <strong>Output</strong> </p> <img src="//techcodeview.com/img/c-tutorial/66/star-patterns-program-c-39.webp" alt="Star Program in C"> <h2 id="Hollow-Inverted-Mirrored-Right-Triangle-Star">Hollow Inverted Mirrored Right Triangle Star Pattern</h2> <p>The code for the hollow inverted mirrored right triangle star pattern is given below:</p> <pre> #include int main() { int n,m; printf(&apos;Enter the number of rows&apos;); scanf(&apos;%d&apos;,&amp;n); m=n; for(int i=1;i<=n;i++) { for(int j="1;j" <i;j++) printf(' '); } k="1;k&lt;=m;k++)" if(i="=1" m--; printf('
'); return 0; < pre> <p> <strong>Output</strong> </p> <img src="//techcodeview.com/img/c-tutorial/66/star-patterns-program-c-40.webp" alt="Star Program in C"> <h2 id="Pyramid-Star">Pyramid Star Pattern</h2> <p>The code for the pyramid star pattern is given below:</p> <pre> #include int main() { int n,m; printf(&apos;Enter the number of rows&apos;); scanf(&apos;%d&apos;,&amp;n); m=n; for(int i=1;i<=n;i++) { for(int j="1;j&lt;=m-1;j++)" printf(' '); } k="1;k&lt;=2*i-1;k++)" printf('*'); m--; printf('
'); return 0; < pre> <p> <strong>Output</strong> </p> <img src="//techcodeview.com/img/c-tutorial/66/star-patterns-program-c-41.webp" alt="Star Program in C"> <h2 id="Hollow-Pyramid">Hollow Pyramid Star Pattern</h2> <p>The code for the hollow pyramid star pattern is given below:</p> <pre> #include int main() { int n,m; printf(&apos;Enter the number of rows&apos;); scanf(&apos;%d&apos;,&amp;n); m=n; for(int i=1;i<=n;i++) { for(int j="1;j&lt;=m-1;j++)" printf(' '); } k="1;k&lt;=2*i-1;k++)" if(k="=1" m--; printf('
'); return 0; < pre> <p> <strong>Output</strong> </p> <img src="//techcodeview.com/img/c-tutorial/66/star-patterns-program-c-42.webp" alt="Star Program in C"> <h2 id="Inverted-Pyramid-Star">Inverted Pyramid Star Pattern</h2> <p>The code for the inverted pyramid is given below:</p> <pre> #include int main() { int n,m=1; printf(&apos;Enter the number of rows&apos;); scanf(&apos;%d&apos;,&amp;n); for(int i=n;i&gt;=1;i--) { for(int j=1;j<m;j++) { printf(' '); } for(int k="1;k&lt;=2*i-1;k++)" printf('*'); m++; printf('
'); return 0; < pre> <p> <strong>Output</strong> </p> <img src="//techcodeview.com/img/c-tutorial/66/star-patterns-program-c-43.webp" alt="Star Program in C"> <h2 id="Hollow-Pyramid-Star">Hollow Pyramid Star Pattern</h2> <p>The code for the hollow pyramid star pattern is given below:</p> <pre> #include int main() { int n,m=1; printf(&apos;Enter the number of rows&apos;); scanf(&apos;%d&apos;,&amp;n); for(int i=n;i&gt;=1;i--) { for(int j=1;j<m;j++) { printf(' '); } for(int k="1;k&lt;=2*i-1;k++)" m++; printf('
'); return 0; < pre> <p> <strong>Output</strong> </p> <img src="//techcodeview.com/img/c-tutorial/66/star-patterns-program-c-44.webp" alt="Star Program in C"> <h2 id="Half-Diamond-Star">Half Diamond Star Pattern</h2> <p>The code for the half diamond star pattern is given below:</p> <pre> #include int main() { int n,m=1; printf(&apos;Enter the number of columns&apos;); scanf(&apos;%d&apos;,&amp;n); for(int i=1;i<=n;i++) { for(int j="1;j=1;i--)" printf('*'); } printf('
'); return 0; < pre> <p> <strong>Output</strong> </p> <img src="//techcodeview.com/img/c-tutorial/66/star-patterns-program-c-45.webp" alt="Star Program in C"> <h2 id="Diamond-Star">Diamond Star Pattern</h2> <p>The code for the diamond star pattern is given below:</p> <pre> #include int main(void) { int n; printf(&apos;Enter the number of rows
&apos;); scanf(&apos;%d&apos;,&amp;n); int spaces=n-1; int stars=1; for(int i=1;i<=n;i++) { for(int j="1;j&lt;=spaces;j++)" printf(' '); } k="1;ki)" spaces="spaces-1;" stars="stars+2;" if(spaces <i) printf('
'); return 0;} < pre> <p> <strong>Output</strong> </p> <img src="//techcodeview.com/img/c-tutorial/66/star-patterns-program-c-46.webp" alt="Star Program in C"> <h2 id="Right-Arrow-Star">Right Arrow Star Pattern</h2> <p>The code of the right arrow star pattern is given below:</p> <pre> #include int main(void) { int n; printf(&apos;Enter the number of columns&apos;); scanf(&apos;%d&apos;,&amp;n); //printing the upper part of the pattern.. for(int i=0;i<n;i++) { for(int j="0;j" <i;j++) printf(' '); } k="1;k&lt;=n-i;k++)" printf('*'); printf('
'); i="1;i&lt;n;i++)" return 0; < pre> <p> <strong>Output</strong> </p> <img src="//techcodeview.com/img/c-tutorial/66/star-patterns-program-c-47.webp" alt="Star Program in C"> <h2 id="Left-Arrow-Star">Left Arrow Star Pattern</h2> <p>The code for the Left arrow star pattern is given below:</p> <pre> #include int main(void) { int n; printf(&apos;Enter the number of columns&apos;); scanf(&apos;%d&apos;,&amp;n); //printing the upper part of the pattern.. for(int i=1;i<=n;i++) { for(int j="1;j&lt;=n-i;j++)" printf(' '); } k="0;k&lt;=n-i;k++)" printf('*'); printf('
'); i="1;i&lt;n;i++)" <i+1;j++) return 0; < pre> <p> <strong>Output</strong> </p> <img src="//techcodeview.com/img/c-tutorial/66/star-patterns-program-c-48.webp" alt="Star Program in C"> <h2 id="Plus-Star">Plus Star Pattern</h2> <p>The code for the plus star pattern is given below:</p> <pre> #include int main(void) { int n; printf(&apos;Enter the odd number only&apos;); scanf(&apos;%d&apos;, &amp;n); for(int i=1;i<=n;i++) { if(i="=((n/2)+1))" for(int j="1;j&lt;=n;j++)" printf('+'); } else printf(' '); printf('
'); return 0; < pre> <p> <strong>Output</strong> </p> <img src="//techcodeview.com/img/c-tutorial/66/star-patterns-program-c-49.webp" alt="Star Program in C"> <h2 id="X-Star">X Star Pattern</h2> <p>The code for the X star pattern is given below:</p> <pre> #include int main(void) { int n,m; printf(&apos;Enter the number&apos;); scanf(&apos;%d&apos;,&amp;n); m=2*n-1; for(int i=1;i<=m;i++) { for(int j="1;j&lt;=m;j++)" if(i="=j" || printf('*'); } else printf(' '); printf('
'); return 0; < pre> <p> <strong>Output</strong> </p> <img src="//techcodeview.com/img/c-tutorial/66/star-patterns-program-c-50.webp" alt="Star Program in C"> <hr></=m;i++)></pre></=n;i++)></pre></=n;i++)></pre></n;i++)></pre></=n;i++)></pre></=n;i++)></pre></m;j++)></pre></m;j++)></pre></=n;i++)></pre></=n;i++)></pre></=n;i++)></pre></=n;i++)></pre></=i;j++)></pre></=i;j++)></pre></=i-1;j++)></pre></=i-1;j++)></pre></=n;i++)></pre></=n;i++)></pre></=n;i++)></pre></=n;i++)></pre></=i-1;j++)></pre></=i-1;j++)></pre></=n;i++)></pre></=n;i++)></pre></n;i++)>