|
发表于 2015-1-17 12:13:53
|
显示全部楼层
- #include <stdio.h>
- #include <math.h>
- #define BITS_PERBYTE 8
- #define MAX_MIN_SIGNED(TYPE) \
- do { \
- TYPE si; \
- si = TYPE(-pow(2, BITS_PERBYTE*sizeof(TYPE)-1)); \
- printf("min value of %s is: %d\n",#TYPE,si); \
- si = TYPE(pow(2, BITS_PERBYTE*sizeof(TYPE)-1)-1); \
- printf("max value of %s is: %d\n", #TYPE, si); \
- si++; \
- printf("max value of %s + 1 is: %d\n", #TYPE, si); \
- } while(0);
- #define MAX_MIN_UNSIGNED(TYPE) \
- do { \
- TYPE ui; \
- ui = 0; \
- printf("min value of %s is: %u\n",#TYPE,ui); \
- ui = TYPE(pow(2, BITS_PERBYTE*sizeof(TYPE))-1); \
- printf("max value of %s is: %u\n", #TYPE, ui); \
- ui++; \
- printf("max value of %s + 1 is: %d\n", #TYPE, ui); \
- } while(0);
- void output_max_min(void);
- void show_ascii(void);
- int main(void) {
- output_max_min();
- show_ascii();
- return 0;
- }
- static void print_delimiter(void);
- void output_max_min(void) {
- print_delimiter();
- MAX_MIN_SIGNED( signed short );
- print_delimiter();
- MAX_MIN_UNSIGNED( unsigned short );
- print_delimiter();
- MAX_MIN_SIGNED( signed int );
- print_delimiter();
- MAX_MIN_UNSIGNED( unsigned int );
- print_delimiter();
- MAX_MIN_SIGNED( signed long );
- print_delimiter();
- MAX_MIN_UNSIGNED( unsigned long );
- print_delimiter();
- }
- void print_delimiter(void) {
- printf("===========================\n");
- }
- static void show_binary( char c );
- void show_ascii(void) {
- int c = 'a';
- while( 1) {
- printf("Please input a char, then enter, input enter to quit:");
- c= getchar();
- if( c == '\n') break;
- printf("input char is : %c, Dec value is: %d, Hex value is: %x, Bin value is:", c, c, c);
- show_binary(c);
- printf("\n");
- getchar();//eat enter
- }
- }
- void show_binary( char c ) {
- if( c == 1 || c == 0 ) putchar(c+'0');
- else {
- show_binary(c/2);
- putchar(c%2+'0');
- }
- }
复制代码 |
|