Last active
August 26, 2018 19:12
-
-
Save lukakostic/937a863f8e1658bdd5af8432572ba603 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
/* | |
Try doing your own to replicate the below output, it took me more than id like to admit ;) (~1-2hrs) | |
lenght = 25 | |
************************* | |
************ ************ | |
*********** *********** | |
********** ********** | |
********* ********* | |
******** ******** | |
******* ******* | |
****** ****** | |
***** ***** | |
**** **** | |
*** *** | |
** ** | |
* * | |
** ** | |
*** *** | |
**** **** | |
***** ***** | |
****** ****** | |
******* ******* | |
******** ******** | |
********* ********* | |
********** ********** | |
*********** *********** | |
************ ************ | |
************************* | |
*/ | |
int dotsOnLine(int n){ | |
if(n == 1) return 0; | |
if(n == 2) return 1; | |
return dotsOnLine(n-1)+2; | |
} | |
int main() | |
{ | |
double lenght = 25; | |
for(double i = 1; i < lenght+1; i++){ | |
double dots = 0; | |
if(i>(lenght/2.0)){ | |
dots = dotsOnLine(lenght-i+1); | |
}else{ | |
dots = dotsOnLine(i); | |
} | |
double spaces = lenght-dots; | |
for(double j = 1; j < lenght+1; j++){ | |
if(j==(lenght/2.0)+0.5) | |
{ | |
if(j<=((spaces/2.0)+0.5)){ | |
printf("*"); | |
}else{ | |
printf(" "); | |
} | |
} | |
else if(j<=(lenght/2.0)) | |
{ | |
if(j<((spaces/2.0)+0.5)){ | |
printf("*"); | |
}else{ | |
printf(" "); | |
} | |
} | |
else | |
{ | |
if((lenght+1-j) <((spaces/2.0)+0.5)){ | |
printf("*"); | |
}else{ | |
printf(" "); | |
} | |
} | |
} | |
printf("\n"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment