c programming language ___ 5_2.c

 #include <stdio.h>
#include <ctype.h>
#define BUG printf("here!bug!\n"); int getfloat(float *pn){
int c;
int t;
int intbeforepoint=;
int intafterpoint=;
int intafterpoint_lenth=;
int inte;
int sign,esign;
int ppoint; // 1 means there have point ,otherwise no
float res=; while( isspace(c=getch()) )
;
if(!isdigit(c)&&c!=EOF&&c!='+'&&c!='-'){
ungetch();
return ;
}
sign=(c=='-')?-:;
if(c=='+'||c=='-')
c=getch();
for(intbeforepoint=;isdigit(c);c=getch())
intbeforepoint=*intbeforepoint+(c-'');
ppoint=;
if(c=='.'){
ppoint=;
c=getch();
for(intafterpoint=;isdigit(c);c=getch()){
intafterpoint=*intafterpoint+(c-'');
intafterpoint_lenth++;
}
t=intafterpoint;
while(t%==){
intafterpoint_lenth--;
t=t/;
}
}
if(c=='e'||c=='E'){
c=getch();
esign=;
if(c=='+'||c=='-'){
esign= (c=='+')?:-;
c=getch();
}
while( c==''){
c=getch();
}
for(inte=;isdigit(c);c=getch())
inte=*inte+(c-'');
}
BUG;
if(c!=EOF)
ungetch(c);
res=1.0*intbeforepoint;
t=intafterpoint_lenth;
while(t--)
res*=;
res+=intafterpoint;
t=intafterpoint_lenth;
while(t--)
res/=;
if(esign==-){
while(inte--)
res/=;
}else if(esign==){
while(inte--)
res*=;
}
res*=sign;
*pn=res;
printf("intbeforepoint=%d\n",intbeforepoint);
printf("intafterpoint=%d\n",intafterpoint);
printf("inte=%d\n",inte);
printf("length=%d\n",intafterpoint_lenth);
return c;
}
int main(){
float num[];
int i;
for(i=;i<;++i){
getfloat(&num[i]);
printf("%lf\n",num[i]);
}
return ;
}

5_2.c

上一篇:帝国cms后台 不同栏目发布字段不同


下一篇:帝国cms相关调用