Created
April 16, 2014 15:21
-
-
Save castaneai/10893120 to your computer and use it in GitHub Desktop.
5 => 1,2,3,4,5,4,3,2,1 のようなピラミッド型ループを作る
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
#include <iostream> | |
#include <functional> | |
using namespace std; | |
void pyramid(int max, function<void(int)> each) | |
{ | |
for (int i = 1; i < max * 2; i++){ | |
each(i - (i / max) * (i % max) * 2); | |
} | |
} | |
int main(void) | |
{ | |
pyramid(9, [](int i) { | |
cout << i << ", "; | |
}); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment