Last active
May 1, 2022 04:08
-
-
Save rubywai/af58d3dc281fa2f47ad3c4cba1a9319d 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
void main() { | |
int n = 4; | |
int besideSq = 2 * beside(n); | |
int middleSq = middle(n); | |
int totalSquares = besideSq + middleSq; | |
print(totalSquares); | |
} | |
int beside(int n){ //numbers of squares from each side | |
int squares = 0; | |
for(int i=1; i<(2 *(n-1)); i+=2){ | |
squares += i; | |
} | |
return squares; | |
} | |
int middle(int n){ //number of squares from middle row | |
return 1 + 2 * (n-1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment