? 编写一个程序以确定分别由signed及unsigned限定的char,short,int,与long类型变量的取值范围
求这个程序 简单点的
#include<stdio.h>
#include<math.h>
int main()//vc版编译器似乎对long型没效,先忽略 long型,但是算法原理时一样的
{
int maxint,minint;
short maxshort,minshort;
unsigned unmaxint,unmaxshort;
char maxchar;
unsigned unmaxchar;
int i;
for (i=maxint=1;maxint>=0;i++)
maxint*=2;
maxint=pow(2,i-1)-1;
minint=-maxint-1;
unmaxint=-minint*2-1;
printf("maxint=%d minint=%d,unmaxint=%u,unminint=0\n",maxint,minint,unmaxint);
for (i=maxshort=1;maxshort>=0;i++)
maxshort*=2;
maxshort=pow(2,i-1)-1;
minshort=-maxshort-1;
unmaxshort=-minshort*2-1;
printf("maxshort=%d,minshort=%d\n",maxshort,minshort);
printf("unmaxshort=%u,unminshort=0\n",unmaxshort);
for (i=maxchar=1;maxchar>=0;i++)
maxchar*=2;
maxchar=pow(2,i-1)-1;
unmaxchar=(maxchar+1)*2-1;
printf("maxchar=%d,maxunchar=%u\n",maxchar,unmaxchar);
printf("minchar=0,unminchar=0\n");
return 0;
}