To print multiple lines of text in C, you can use the printf() function and include newline characters (\n) in your text. Each newline character moves the cursor to the beginning of the next line.
Here's an example:
#include <stdio.h>
int main() {
printf("This is line 1.\n");
printf("This is line 2.\n");
printf("This is line 3.\n");
return 0;
}
In this example, three separate printf() statements are used to print multiple lines of text. The newline character \n is added at the end of each line to start a new line.
The output will be:
This is line 1.
This is line 2.
This is line 3.
Alternatively, you can use a single printf() statement and include newline characters within the text using escape sequences. Here's an example:
#include <stdio.h>
int main() {
printf("This is line 1.\nThis is line 2.\nThis is line 3.\n");
return 0;
}
In this example, the newline characters \n are placed directly within the string to create line breaks. This results in the same output as the previous example.
You can add as many lines of text as needed, simply by including newline characters (\n) in the appropriate positions within the printf() statements.