Bird
0
0

You want to print a table of numbers and their squares using printf. Which code snippet correctly prints the number 4 and its square 16 in the format "4 squared is 16"?

hard📝 Application Q8 of 15
C - Input and Output
You want to print a table of numbers and their squares using printf. Which code snippet correctly prints the number 4 and its square 16 in the format "4 squared is 16"?
Aprintf("%d squared is %d", 4, 16);
Bprintf("%d squared is %d", "4", "16");
Cprintf("4 squared is 16");
Dprintf("%s squared is %s", 4, 16);
Step-by-Step Solution
Solution:
  1. Step 1: Check format specifiers and arguments

    printf("%d squared is %d", 4, 16); uses %d for integers 4 and 16, which matches the data types correctly.
  2. Step 2: Analyze other options for errors

    printf("%d squared is %d", "4", "16"); passes strings instead of integers, printf("4 squared is 16"); prints fixed text without variables, printf("%s squared is %s", 4, 16); uses %s for integers which is incorrect.
  3. Final Answer:

    printf("%d squared is %d", 4, 16); -> Option A
  4. Quick Check:

    Use %d for integers and pass matching arguments [OK]
Quick Trick: Match %d with integers, %s with strings in printf [OK]
Common Mistakes:
  • Passing strings for integers
  • Using wrong format specifiers
  • Not passing variables

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes