There is such a task:

Starting training, the athlete on the first day ran 10 km. Every day he increased the rate by 10% of the rate of the previous day. What is the total path the athlete runs in 7 days?

Need to solve with a for loop. I understand that the cycle will be something like this:

 s=10 k=10 for(k=s*0,1+k) s+=s*0,1 

And how can I display the result here? Need to set a variable, or how?

    1 answer 1

    Well, as if, yes, the idea is correct, only it was necessary to record everything correctly.

     #include <stdio.h> int main(void) { float today, total; unsigned int day; /* Ситуация на первый день. Пробежали 10 км, как за день, так и всего. */ total = today = 10.0; /* Цикл со 2 по 7 дни, включительно. */ for (day = 2; day <= 7; day++) { /* Каждый очередной день пробегаем 110% от предыдущего дня. Можно было написать хоть today = today + today * 0.1, но это некрасиво. */ today *= 1.1; /* Добавляем пробег очередного дня */ total += today; /* Выводим промежуточный результат. Вообще, он не нужен — это только, чтобы запустить и посмотреть как в цикле все происходило. Потом убрать. */ printf("day %d: %0.2f km, total: %0.2f km\n", day, today, total); } /* Собственно, выводим суммарный пробег. */ printf("%0.2f km\n", total); return 0; } 
    • Why display intermediate results? Take out the "print" for the cycle. - Specter
    • hmm :) good person, could you write comments to the program, otherwise I didn’t understand everything :) in particular, what do these lines mean?) today * = 1.1; total + = today; - Timi
    • For clarity, to run and see how it changes inside. And then he will figure out where to push printf , tea move the line - not rocket science. - drdaeman Sep.
    • Or maybe! all perfectly! Thanks to everyone :) I understood everything!) and the print was made for the cycle ... everything was okay :) to everyone, ATP)) - Timi
    • mark this answer as “Right” - Specter