Kodewick
Commencer à apprendre →
Débutant←→0 / 50

s = a + aa + aaa

#027Débutantterm * 10 + a5 min

a est un chiffre (0–9) : calcule s = a + aa + aaa + …, avec n termes au total, le terme i étant formé de i fois le chiffre a. Écris sum_a(a, n). Par exemple, avec a = 2, n = 5 : 2 + 22 + 222 + 2222 + 22222 = 24690. Les nombres deviennent grands, d’où long long.

Exemples
sum_a(2, 5)→24690
sum_a(1, 3)→123
La fonctionlong long sum_a(int a, int n)
main.c
long long sum_a(int a, int n) {
    long long term = 0, s = 0;
    for (int i = 1; i <= n; i++) {
        // ton code ici: ajoute un a à la fin de term, puis ajoute term à s
    }
    return s;
}
Ctrl + Entrée lance aussi le code
Résultat

Exécuter teste les exemples. Quand ils sont bons, appuie sur Envoyer.