변환지정에 대한질문..
리카
#include stdio.h
int main(void)
{
printf([%d]\n, 123);
printf([%.4d]\n, 123);
printf([%4d]\n, 123);
printf([%04d]\n, 123);
printf([%-4d]\n\n, 123);
printf([%d]\n, 12345);
printf([%.3d]\n, 12345);
printf([%3d]\n, 12345);
printf([%03d]\n, 12345);
printf([%-3d]\n\n, 12345);
printf([%f]\n, 123.13);
printf([%.1f]\n, 123.13);
printf([%6.1f]\n\n, 123.13);
printf([%f]\n, 123.13);
printf([%.1f]\n, 123.13);
printf([%4.1f]\n\n, 123.13);
getch();
return (0);
}예제가 이거에요..
근데 컴파일하면 실행결과가
123
0123
123
0123
123
12345
12345
12345
12345
12345
123.130000
123.1
123.1
123.130000
123.1
123.1
이거입니다.. 근데 저게 뭔소리죠?? 대괄호 안에 %.4d나 04d이런건뭐죠?
-
바름
%04d는요 4칸에 넣겠다라는 뜻이고요 남는 자리는 0으로 채우겠다란 뜻입니다^^
%.1f 이것이 실수형에서 소수점 2자리에서 반올림해서 1자리까지 나타낸다는 말인데요
%.4d 도 소수점 4자리에서 반올림하는것일텐데... 정수니까 필요없겠죠?