1: write a program to determine the value range of the char short long int defined by signed and unsigned respectively. You can print the corresponding values in the standard header file and calculate them directly.
Header file implementation:
#include <stdio.h>#include <limits.h>/*determin range of int types*/int main(){ /*signed*/ printf("signed char min = %d\n",SCHAR_MIN); printf("signed char max = %d\n",SCHAR_MAX); printf("signed short min = %d\n",SHRT_MIN); printf("signed short max = %d\n",SHRT_MAX); printf("signed int min = %d\n",INT_MIN); printf("signed int max = %d\n",INT_MAX); printf("signed long min = %ld\n",LONG_MIN); printf("signed long max = %ld\n",LONG_MAX); /*unsigned*/ printf("signed char max=%u\n",UCHAR_MAX); printf("signed short max = %u\n",USHRT_MAX); printf("signed int max = %u\n",UINT_MAX); printf("signed long max = %lu\n",ULONG_MAX); getchar(); return 0;}
Direct computing:
# Include <stdio. h> /*~ 0 returns all digits to 1 (unsigned char )~ 0 to unsigned char )~ 0> 1 shift one digit to the right to clear the sign (char) (unsigned char )~ 0> 1 convert to char type */INT main () {/* singed */printf ("min of singed char = % d \ n",-(char) (unsigned char )~ 0> 1); printf ("max of singed char = % d \ n", (char) (unsigned char )~ 0> 1); printf ("min of singed short = % d \ n",-(short) (unsigned short )~ 0> 1); printf ("max of singed short = % d \ n", (short) (unsigned short )~ 0> 1); printf ("min of singed Int = % LD \ n",-(INT) (INT long )~ 0> 1); printf ("max of singed Int = % LD \ n", (INT) (INT long )~ 0> 1); printf ("min of singed long = % LD \ n",-(long) (unsigned long )~ 0> 1); printf ("max of singed long = % LD \ n", (long) (unsigned long )~ 0> 1);/* unsigned */printf ("max of singed char = % u \ n", (unsigned char )~ 0); printf ("max of singed char = % u \ n", (unsigned short )~ 0); printf ("max of singed char = % u \ n", (unsigned INT )~ 0); printf ("max of singed char = % lu \ n", (unsigned long )~ 0); getchar (); Return 0 ;}