課題:Mario More
課題は、マリオブラザーズでお馴染みのブロックを「#」を使って作るというもの。
https://cs50.harvard.edu/x/2021/psets/1/mario/more/

回答例
#include <cs50.h>
#include <stdio.h>
int main(void)
{
// Promt user for input
int n;
do
{
n = get_int("Height: ");
}
while (n < 1 || n > 8);
// Outer loop
for (int i = 0; i < n; i++)
{
// Inner loop, print space
for (int j = 0; j < n - i - 1; j++)
{
printf(" ");
}
// print uphill hashtag #
for (int k = 0; k <= i; k++)
{
printf("#");
}
// gap in between
printf(" ");
// print downhill hashtag #
for (int l = 0; l <= i; l++)
{
printf("#");
}
// New line
printf("\n");
}
}
未希 諒
香港在住の34歳サラリーマン。戦略家、写真家、旅人、サウナー。 2025年までに季節を選びながら世界中を飛び回る仕事をするために準備中。その道中で発見した気づきや気になる話題を中心に発信しています。2010年より旅をスタートし通算500箇所の宿に宿泊。年間の3分の1をホテルで暮らす。
Related posts
About media
Ramps Blog は、ノマドによるノマドのためのブログです。日本、香港、シンガポール、タイ、台湾のノマド生活を通じて見えた景色、特に食、カルチャー、テクノロジー、ビジネス、アート、デザインなどについて発信しています。
Recent Posts
Twitter feed is not available at the moment.