Chapter 3. The
Fundamental Data Types
Home
decimal, binary, hexadecimal
numbers list
|
decimal |
binary |
hexadecimal |
|
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 |
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111 |
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F |
single-precision
floating-point numbers
double-precision
floating-point numbers
|
/* Compute the size of some fundamental types. */
#include <stdio.h>
int main(void)
{
printf("The size of some fundamental types is computed.\n\n");
printf(" char:%3d byte \n", sizeof(char));
printf(" short:%3d bytes\n", sizeof(short));
printf(" int:%3d bytes\n", sizeof(int));
printf(" long:%3d bytes\n", sizeof(long));
printf(" unsigned:%3d bytes\n", sizeof(unsigned));
printf(" float:%3d bytes\n", sizeof(float));
printf(" double:%3d bytes\n", sizeof(double));
printf("long double:%3d bytes\n", sizeof(long double));
return 0;
}
|
กก
|
PROGRAM 32 : double_out.c
|
|
#include <stdio.h>
int main(void)
{
int c;
while ((c = getchar()) != EOF) {
putchar(c);
putchar(c);
}
return 0;
}
|
|
PROGRAM 33 : capitalize.c
|
|
#include <stdio.h>
int main(void)
{
int c;
while ((c = getchar()) != EOF)
if (c >= 'a' && c <= 'z')
putchar(c + 'A' - 'a');
else
putchar(c);
return 0;
}
|
|
#include <math.h>
#include <stdio.h>
int main(void)
{
double x;
printf("\n%s\n%s\n%s\n\n",
"The square root of x and x raised",
"to the x power will be computed.",
"---");
while (1) { /* do it forever */
printf("Input x: ");
scanf("%lf", &x);
if (x >= 0.0)
printf("\n%15s%22.15e\n%15s%22.15e\n%15s%22.15e\n\n",
"x = ", x,
"sqrt(x) = ", sqrt(x),
"pow(x, x) = ",
pow(x, x));
else
printf("\nSorry, your number must be nonnegative.\n\n");
}
return 0;
}
|
|
/* Decimal, hexadecimal, octal conversions. */
#include <stdio.h>
int main(void)
{
printf("%d %x %o\n", 19, 19, 19); /* 19 13 23 */
printf("%d %x %o\n", 0x1c, 0x1c, 0x1c); /* 28 1c 34 */
printf("%d %x %o\n", 017, 017, 017); /* 15 f 17 */
printf("%d\n", 11 + 0x11 + 011); /* 37 */
printf("%x\n", 2097151); /* 1fffff */
printf("%d\n", 0x1FfFFf); /* 2097151 */
return 0;
}
|
|
#include <stdio.h>
int main(void)
{
printf("sizeof('A') = %d\n", sizeof('A'));
return 0;
}
|
|
#include <limits.h> /* for UINT_MAX */
#include <stdio.h>
int main(void)
{
int i;
unsigned u = UINT_MAX; /* typically 4294967295 */
for (i = 0; i < 10; ++i)
printf("%u + %d = %u\n", u, i, u + i);
for (i = 0; i < 10; ++i)
printf("%u * %d = %u\n", u, i, u * i);
return 0;
}
|
[Last Update: 2001.2.20] Dongseo University Cyber Campus
|