Last active
August 29, 2015 14:06
-
-
Save ryunp/fff29e3b67a9f77493c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* File: main.c | |
* Author: Ryan | |
* | |
* Created on September 6, 2014, 1:01 PM | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
/* | |
* data[] is the input array | |
* result[][] is the output array | |
* | |
* dSize is number of data elements in data[] | |
* rSize is number of data elements in result[] | |
* | |
*/ | |
int main(int argc, char** argv) { | |
// Setup environment | |
int data[] = {1,2,3,4}, | |
dSize = sizeof data / sizeof data[0], | |
rSize = 2 * dSize - 1, | |
result[rSize][rSize], | |
i, j, k, | |
startDex=0, endDex=rSize; | |
// Flood double dimension array with input data | |
for (i=0; i < dSize; i++) { // Traverse input array | |
for (j=startDex; j < endDex; j++) { // Y axis | |
for (k=startDex; k < endDex; k++) { // X axis | |
result[j][k] = data[i]; | |
} | |
} | |
startDex++; | |
endDex--; | |
} | |
// Print results | |
printf("{"); | |
for (i=0; i < rSize; i++) { | |
if ( i > 0) { printf(" "); } // Conditional formatting | |
printf("{"); | |
for (j=0; j < rSize; j++) { | |
printf("%d", result[i][j]); | |
if (j < rSize-1) { printf(" "); } // Conditional formatting | |
} | |
printf("}"); | |
if (i < rSize-1) { printf("\n"); } // Conditional formatting | |
} | |
printf("}\n\n"); | |
return (EXIT_SUCCESS); | |
} | |
/** | |
* INPUT: {1,2,3,4} | |
* OUTPUT: | |
* | |
* {{1 1 1 1 1 1 1} | |
* {1 2 2 2 2 2 1} | |
* {1 2 3 3 3 2 1} | |
* {1 2 3 4 3 2 1} | |
* {1 2 3 3 3 2 1} | |
* {1 2 2 2 2 2 1} | |
* {1 1 1 1 1 1 1}} | |
* | |
*RUN SUCCESSFUL (total time: 21ms) | |
*/ | |
/** | |
* INPUT: {1,2,3,4,5,6,7,8,9} | |
* OUTPUT: | |
* | |
*{{1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1} | |
* {1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1} | |
* {1 2 3 3 3 3 3 3 3 3 3 3 3 3 3 2 1} | |
* {1 2 3 4 4 4 4 4 4 4 4 4 4 4 3 2 1} | |
* {1 2 3 4 5 5 5 5 5 5 5 5 5 4 3 2 1} | |
* {1 2 3 4 5 6 6 6 6 6 6 6 5 4 3 2 1} | |
* {1 2 3 4 5 6 7 7 7 7 7 6 5 4 3 2 1} | |
* {1 2 3 4 5 6 7 8 8 8 7 6 5 4 3 2 1} | |
* {1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1} | |
* {1 2 3 4 5 6 7 8 8 8 7 6 5 4 3 2 1} | |
* {1 2 3 4 5 6 7 7 7 7 7 6 5 4 3 2 1} | |
* {1 2 3 4 5 6 6 6 6 6 6 6 5 4 3 2 1} | |
* {1 2 3 4 5 5 5 5 5 5 5 5 5 4 3 2 1} | |
* {1 2 3 4 4 4 4 4 4 4 4 4 4 4 3 2 1} | |
* {1 2 3 3 3 3 3 3 3 3 3 3 3 3 3 2 1} | |
* {1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1} | |
* {1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1}} | |
* | |
* | |
*RUN SUCCESSFUL (total time: 25ms) | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment