View Code of Problem 57

#include <stdio.h>
#include <math.h>
main(){
	int t,i,j,a[20];
	scanf("%d",&t);
	a[0] = 1;
	for(i = 1;i<(2*t)-1;i++)
		a[i] = a[i-1]+2; 	
	for(i=0;i<(2*t)-1;i++){
		int k =1,g=1;
		for(j = 0;j<abs(t-i-1);j++)
			printf(" ");
		if(i<t){
			for(j = 0;j<a[i];j++){
				if(j<=a[i]/2){
					printf("%d",k);
					k++;
				}
				else{
					printf("%d",k-2);
					k--;
				}
			}
		}
		else{
			for(j = 0;j<a[2*t-i-2];j++){
				if(g<=2*t-i-1){
					printf("%d",g);
					g++;
				}
				else{
					printf("%d",g-2);
					g--;
				}
			}
		}
		printf("\n");
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 57