Lab 1

8/29/02 Thu

  1. Formatting numbers for printf

Formatting numbers for printf

The C standard library function "printf" takes a string with place holders to display numbers. printf displays the numbers differently depending on the type of place holder.

int main()
{
        int x = 6786;
	unsigned int x_u = 6786;
	long y = -9909904323243;
	unsigned long y_u = 9909904323242;
        printf("In signed decimal: x = %d\n", x);
        printf("In unsigned decimal: x_u = %u\n", x_u);
        printf("In long: y = %ld\n", y);
        printf("In unsigned long: y_u = %lu\n", y_u);
        printf("In hexadecimal: x = %x\n", x);
        printf("In hexadecimal: y = %lx\n", y);

        return 0;
}
Back to Top

Revised: 08/28/02 .