#include <stdio.h>
// 関数のプロトタイプ宣言
int sum_sequence(int n);
int main() {
int n, result;
// n = 4 の場合
n = 4;
result = sum_sequence(n);
printf("n=%d の場合の合計は %d\n", n
, result
);
// n = 5 の場合
n = 5;
result = sum_sequence(n);
printf("n=%d の場合の合計は %d\n", n
, result
);
return 0;
}
// 関数の定義
int sum_sequence(int n) {
int total = 0;
int current_term = 0;
int i;
for (i = 1; i <= n; ++i) {
current_term = current_term * 10 + 4;
total += current_term;
}
return total;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgovLyDplqLmlbDjga7jg5fjg63jg4jjgr/jgqTjg5flrqPoqIAKaW50IHN1bV9zZXF1ZW5jZShpbnQgbik7CgppbnQgbWFpbigpIHsKICAgIGludCBuLCByZXN1bHQ7CgogICAgLy8gbiA9IDQg44Gu5aC05ZCICiAgICBuID0gNDsKICAgIHJlc3VsdCA9IHN1bV9zZXF1ZW5jZShuKTsKICAgIHByaW50Zigibj0lZCDjga7loLTlkIjjga7lkIjoqIjjga8gJWRcbiIsIG4sIHJlc3VsdCk7CgogICAgLy8gbiA9IDUg44Gu5aC05ZCICiAgICBuID0gNTsKICAgIHJlc3VsdCA9IHN1bV9zZXF1ZW5jZShuKTsKICAgIHByaW50Zigibj0lZCDjga7loLTlkIjjga7lkIjoqIjjga8gJWRcbiIsIG4sIHJlc3VsdCk7CgogICAgcmV0dXJuIDA7Cn0KCi8vIOmWouaVsOOBruWumue+qQppbnQgc3VtX3NlcXVlbmNlKGludCBuKSB7CiAgICBpbnQgdG90YWwgPSAwOwogICAgaW50IGN1cnJlbnRfdGVybSA9IDA7CiAgICBpbnQgaTsKCiAgICBmb3IgKGkgPSAxOyBpIDw9IG47ICsraSkgewogICAgICAgIGN1cnJlbnRfdGVybSA9IGN1cnJlbnRfdGVybSAqIDEwICsgNDsKICAgICAgICB0b3RhbCArPSBjdXJyZW50X3Rlcm07CiAgICB9CgogICAgcmV0dXJuIHRvdGFsOwp9Cg==