View Code of Problem 57

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>

char a[105], b;

int main()
{
    int n;
    while (scanf("%d", &n) != EOF) {
        int k = n -1;
        while (k >= 0) {
            for (int i = 0; i < k; i++) {
                putchar(' ');
            }
            
            for (int i = 1; i <= n - k; i++) {
                printf("%d", i);
            }
            
            for (int i = n - k - 1; i >= 1; i--) {
                printf("%d", i);
            }
            putchar('\n');
            k--;
        }
        
        for (int i = 1; i <= n - 1; i++) {
            for (int j = 0; j < i; j++) {
                putchar(' ');
            }
            
            for (int j = 1; j <= n - i; j++) {
                printf("%d", j);
            }
            
            for (int j = n - i - 1; j >= 1; j--) {
                printf("%d", j);
            }
            putchar('\n');
        }
    }
}

Double click to view unformatted code.


Back to problem 57