# My challenge to everyone on this forum

 Lazar Bulic · January 24, 2015 The task is simple:Users inserts an whole number N. Print a square  matrix using this pattern. Example is give for N = 4 Let the games begin

## Replies

- page 2

 Kevin Faust · February 9, 2015 Nishant huh we think alike! I think thats very cool. I got mine to work in the same way you did but in C however mines a bit broken since when it goes into the inner wrapping, it breaks. Lazar Bulic · February 9, 2015 Can you post the C code Kevin? Luka Lopotar · February 9, 2015 Okay, here is the code for the second one: http://pastebin.com/Mn9DJpe4Still figuring out the first one though. Not giving up yet  . Some hints? Lazar Bulic · February 9, 2015 ---------------------------------------------Spoiler---------------------------------------------------------------------------------------------------Spoiler------------------------------------------------------ Lazar Bulic · February 9, 2015 Also @Luka Lopotar thanks for your solution of second matrix. I never saw the this way of declaring a matrix. Will need to dig in to it a bit I think its a little more complicated the mine but its really good optimized.And don't forget to free you memory!!!! Kevin Faust · February 9, 2015 I solved it in C!EDIT: I just realized it won't work for some numbers like 5 as shown below. God dam!#include #include "string.h"#define NAME "KEVIN"int main(int argc, const char * argv[]) {    int number;        printf("Enter your desired number! \n");    scanf(" %d", &number);        int square[number][number];        for(int i = 0; i != number; i ++) {        for(int j = 0; j != number; j ++) {            square[j] = 0;        }    }        int direction = 0;    /*     0 | RIGHT     1 | DOWN     2 | LEFT     3 | UP     */        int counter = 0;    int currentX = 0;    int currentY = 0;    for(int i = 0; i != number * number + number; i ++) {        counter ++;                square[currentX][currentY] = counter;                switch (direction) {            case 0:                if(square[currentX + 1][currentY] == 0) {                    currentX ++;                    break;                } else {                    direction ++;                }            case 1:                if(square[currentX][currentY + 1] == 0) {                    currentY ++;                    break;                } else {                    direction ++;                }            case 2:                if(square[currentX - 1][currentY] == 0) {                    currentX--;                    break;                } else {                    direction ++;                }            case 3:                if(square[currentX][currentY - 1] == 0) {                    currentY --;                    break;                } else {                    counter --;                    direction = 0;                }        }    }        for(int i = 0; i != number; i ++) {        for(int j = 0; j != number; j ++) {            square[j] > 9 ? printf(" %d", square[j]) : printf("  %d", square[j]);        }        printf(" \n");    }        return 0;} Bernhard Riemann Georg Friedrich · July 6, 2015 Looks like a Pascal's triangle, problem solved ,I also stumbled across that while watching the table video on C.
• 1
• 2

## C

130,978 followers