Here's a program to print a simple diamond pattern of numbers:
#include <stdio.h>
int main() {
int n, space, number, i, j;
printf("Enter the number of rows: ");
scanf("%d", &n);
for (i = 1; i <= n; i++) {
// Print spaces before the numbers
for (space = 1; space <= n - i; space++) {
printf(" ");
}
// Print ascending numbers
for (j = 1, number = 1; j <= 2 * i - 1; j++, number++) {
printf("%2d", number);
}
printf("\n");
}
for (i = n - 1; i >= 1; i--) {
// Print spaces before the numbers
for (space = 1; space <= n - i; space++) {
printf(" ");
}
// Print ascending numbers
for (j = 1, number = 1; j <= 2 * i - 1; j++, number++) {
printf("%2d", number);
}
printf("\n");
}
return 0;
}
This program will create a diamond pattern of numbers based on the number of rows you input. It prints ascending numbers in the top half and descending numbers in the bottom half.
For example, if you input 5 for the number of rows, the program will generate the following diamond pattern:
1
123
12345
1234567
123456789
1234567
12345
123
1
You can adjust the number of rows by changing the value you enter when prompted.