Bird
0
0

You want to write a C program that prints two lines: "Hello!" and "Welcome to C." Which code snippet correctly does this?

hard📝 Application Q15 of 15
C - Basics and Execution Environment
You want to write a C program that prints two lines: "Hello!" and "Welcome to C." Which code snippet correctly does this?
A#include <stdio.h> int main() { printf("Hello!\n"); printf("Welcome to C.\n"); return 0; }
B#include <stdio.h> int main() { printf("Hello!Welcome to C.\n"); return 0; }
C#include <stdio.h> int main() { printf("Hello!"); printf("Welcome to C.\n"); return 0; }
D#include <stdio.h> int main() { printf("Hello!"); printf("Welcome to C."); return 0; }
Step-by-Step Solution
Solution:
  1. Step 1: Understand how to print two lines

    Each line should end with a newline character \n to move to the next line.
  2. Step 2: Check each option for correct newlines

    #include int main() { printf("Hello!\n"); printf("Welcome to C.\n"); return 0; } prints "Hello!" with \n and "Welcome to C." with \n, so two lines appear.
  3. Final Answer:

    Two printf statements, each ending with \n -> Option A
  4. Quick Check:

    Use \n at end of each line for separate lines [OK]
Quick Trick: Use \n after each line to print on new lines [OK]
Common Mistakes:
  • Missing \n causing lines to join
  • Putting \n only on first line
  • Not returning 0 at end of main

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes