Complementary task for topic: 1
M Nemeth · 2023-08-29 15:21:04.602220'
Printf: text, newline
Printf: text, newline
Print multiple lines with newlines:
Write a C program that uses printf() to display multiple lines of text with newlines.
Output like this:
Line 1.
Line 2.
Line 3.
Hint:
The \n creates a newline (newline character, enter...)
Usually we can add white space characters with \, therefore the printf("\") results in error.
To print a backslash you need to use \\ e.g.: printf("\\") will print out: \
Solution
#include
int main() {
printf("Line 1\n");
printf("Line 2\n");
printf("Line 3\n");
return 0;
}
Explanation
In this example, the program uses printf() to display multiple lines of text. Each line is printed using a separate printf() statement, and the newline character \n is added at the end of each line to create a newline.