Please read the new rule regarding the restriction on the use of AI tools. ×

How do you print a new line??

Revision en1, by Naaz, 2023-06-24 10:28:36

can you please tell me how do you print new line. after a a for loop.

	for (int i = 0; i < n; i++) {
		cout << i << " \n"[i == n - 1];
	}

As you can see in the above code it automatically prints newline when i == n-1. and I don't prefer to use ternery operator for this case. (It takes time to write. haha) But can this be done with printf(); Just asking. If it can be done please tell me how?

Happy Coding.

P.S : I use FastOlympicCoding extension in sublime text so it kind of takes into consideration the extra white at the end and does not give correct answer verdict.But the code snippet above mentioned it does not.

Tags help, syntax, beginner

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English Naaz 2023-06-24 10:28:36 687 Initial revision (published)