Here's a simple C code snippet to print a diamond shape using asterisks:
<code class="language-c">#include <stdio.h>int main() { int n = 5; // Number of rows for the upper half for (int i = 1; i <= n; i++) { for (int j = i; j < n; j++) printf(" "); for (int j = 1; j < 2 * i; j++) printf("*"); printf("\n"); } for (int i = n - 1; i >= 1; i--) { for (int j = n; j > i; j--) printf(" "); for (int j = 1; j < 2 * i; j++) printf("*"); printf("\n"); } return 0; }
</code>
This code creates a diamond shape with a specified number of rows in its upper half. Adjust the value of n to change the size of the diamond.
Copyright © 2026 eLLeNow.com All Rights Reserved.