View Code of Problem 57

#include<stdio.h>
#include<math.h>
#include<ctype.h>
#include<string.h>
#include<iostream>
using namespace std;
#include<algorithm>
int main()
{
	int n = 0;
	cin>>n ;
	
	for (int k = 1 - n; k <= n - 1; k++)
	{
		int a = 1;
		int i = n - abs(k);
		for (int j = abs(k); j >= 1;j--)
		{
			printf(" ");
		}
		for (int j = 1; j <= 2 * i - 1; j++)
		{
			if (j <= (2 * i - 1) / 2)
			{
				printf("%d", a++);
			}
			else
			{
				cout <<a--;
			}
		}
		printf("\n");
	}

}

Double click to view unformatted code.


Back to problem 57