Use app×
QUIZARD
QUIZARD
JEE MAIN 2026 Crash Course
NEET 2026 Crash Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
+1 vote
3.6k views
in C Programming by (178k points)
How do I print multiple lines of text?

Please log in or register to answer this question.

1 Answer

0 votes
by (178k points)

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.

Related questions

+1 vote
1 answer
+1 vote
1 answer
+1 vote
1 answer
asked May 22, 2023 in C Programming by kvdevika (178k points)

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...