Skip to the task
Layout
Back to classic view

You are looking at lesson 1. Your place is still lesson 4, task 1: Style.

EDITTask 6 of 21 · step 4: An algorithm as a sequence of statementsPrint the algorithm step by step
Print the algorithm step by step in practice/01/

After "Hello, world!" add an empty line and the steps of the average algorithm, each in its own printf.

Checklist

  • Every task is one commit with a clear message.
Details & hint

A C program is a sequence: statements run one after another, top to bottom. printf("\n"); prints only a new line, so an empty line appears in the output.

Try it: swap two printf lines and run. The steps are printed in the order they are written. Then put them back.

practice 01 main.c Code Diff +6
M · MODIFIED Green = add, blue = change, red mark = removed line.
#include <stdio.h>
int main(void) {
printf("Hello, world!\n");
printf("\n");
printf("Algorithm: the average of grades\n");
printf("1. Add up all the grades.\n");
printf("2. Count how many grades there are.\n");
printf("3. Divide the sum by the count.\n");
printf("4. Print the answer.\n");
return 0;
}