C Programming 2024 New Syllabus Solution
12. Escape Sequences in C Escape sequences are combinations of characters that represent special characters in strings and character literals. They begin with a backslash (). Two examples: \n – Newline: Moves the cursor to the beginning of the next line
1 |
<span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"Hello\nWorld"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Prints Hello and World on separate lines</span> |
\t – Horizontal tab: Inserts a tab space
1 |
<span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"Name:\tJohn"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Prints "Name: John" with tab space</span> |
13. Nested Loop Example
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#include <stdio.h> int main() { // Print multiplication tables from 1 to 5 for(int i = 1; i <= 5; i++) { printf("Multiplication table of %d:\n", i); for(int j = 1; j <= 10; j++) { printf("%d x %d = %d\n", i, j, i*j); } printf("\n"); } return 0; } |
[…]
Continue Reading