// printf, d,f,e,s,d,o,x,u<br>แสดงการกำนหนดการแสดงผลของตัวเลขแบบต่าง ๆ
/* http://www.thaiall.com/tc */
#include <stdio.h>
#include <conio.h>
void main()
{
int i;
i = 1;
printf("number = [%1d]\n",i); // [1]
printf("number = [%2d]\n",i+1); // [ 2]
printf("number = [%3d]\n",i+3); // [ 4]
printf("number = [%-4d]\n",i); // [1 ]
printf("number = [%10.2f]\n",3.159); // [ 3.16]
printf("number = [%4.2f]\n",3.159); // [3.16]
printf("number = [%f]\n",3.159); // [3.159000]
printf("number = [%e]\n",3.159); // [3.159000e+00]
printf("[%5s]\n","a"); // [ a]
printf("[%-5s]\n","a"); // [a ]
printf("%d\n",65); // 65
printf("%o\n",11); // 13
printf("%x\n",65); // 41
printf("%u\n",65); // 65
printf("%u\n",-5); // 65531
printf("%u\n",-1); // 65535
getch();
}
| |