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:
Step 1: Understand how to print two lines
Each line should end with a newline character \n to move to the next line.
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.
Final Answer:
Two printf statements, each ending with \n -> Option A
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
Master "Basics and Execution Environment" in C
9 interactive learning modes - each teaches the same concept differently