PRO
睿宏
asked

Expert
Palistha Singh answered
Hi! You usually should not add \n after %d in scanf.
%d already skips leading whitespace (spaces, tabs, newlines). If you write scanf("%d\n", &x);, that \n tells scanf to keep waiting for more whitespace after the number, and it can look like the program is stuck until you press Enter again or type something else.
So use this:
scanf("%d", &ages[i]);
If you want each input on a new line, that’s handled by how the user types, not by adding \n to scanf.
C
This question was asked as part of the Learn C Programming course.
Our Experts
Sudip BhandariHead of Growth/Marketing
Apekchhya ShresthaSenior Product Manager
Kelish RaiTechnical Content Writer
Abhilekh GautamSystem Engineer
Palistha SinghTechnical Content Writer
Sarthak BaralSenior Content Editor
Saujanya Poudel
Abhay Jajodia
Nisha SharmaTechnical Content Writer
Udayan ShakyaTechnical Content Writer