Difficulty: Easy
Correct Answer: scanf("%f %lf", &a, &b);
Explanation:
Introduction / Context:Correct conversion specifiers are essential when using scanf in C to avoid undefined behavior and corrupted inputs. In particular, float and double have different specifiers in scanf because arguments are not promoted the same way at input time as they are at output time with printf.
Given Data / Assumptions:
Concept / Approach:
Step-by-Step Solution:
Match a (float) → %f.Match b (double) → %lf.Therefore, the correct call is scanf("%f %lf", &a, &b);Verification / Alternative check:
Attempting scanf("%f %f", &a, &b) misreads b because %f expects float*, not double*.Why Other Options Are Wrong:
Common Pitfalls:
Final Answer:
scanf("%f %lf", &a, &b);
Discussion & Comments