How to print numbers palindrome triangle pattern in C

1 Answer

0 votes
#include <stdio.h>

void print_palindrome_triangle_pattern(int rows) {
    int count = 0;

    for (int i = 0; i < 2 * rows; i = i + 2) {
        for (int j = 0; j <= i; j++) {
            printf("%d ", 1 + count);
            if (j < i / 2)
                count++;
            else
                count--;
        }
        count = 0;
        printf("\n");
    }
}
int main() {
    print_palindrome_triangle_pattern(7);

    return 0;
}





/*
run:

1 
1 2 1 
1 2 3 2 1 
1 2 3 4 3 2 1 
1 2 3 4 5 4 3 2 1 
1 2 3 4 5 6 5 4 3 2 1 
1 2 3 4 5 6 7 6 5 4 3 2 1 

*/

 



answered Sep 15, 2023 by avibootz

Related questions

1 answer 102 views
1 answer 103 views
1 answer 95 views
1 answer 136 views
1 answer 161 views
1 answer 132 views
1 answer 116 views
...