// 错误写法
void zero( char str[] )
{
memset( str,0,sizeof(str) );
}
'数组传参之后就变成指针了 sizeof不能得到数组的长度 只能得到指针的长度'
// 实数加法
#include
using namespace std;
const int MAXN=222;
char str1[MAXN],str2[MAXN];
char A[MAXN],a[MAXN],B[MAXN],b[MAXN],ANS[MAXN],ans[MAXN]; // char
int Alen,alen,Blen,blen,ANSlen,anslen;
// 整数部分有最高位进位问题 ( 小数部分进位至个位 )
void solve()
{
int i,pos;
pos=0; for( i=0;str1[i]!='.';i++ ) A[pos++]=str1[i]; Alen=pos;
pos=0; for( i++;str1[i];i++ ) a[pos++]=str1[i]-'0'; alen=pos;
pos=0; for( i=0;str2[i]!='.';i++ ) B[pos++]=str2[i]; Blen=pos;
pos=0; for( i++;str2[i];i++ ) b[pos++]=str2[i]-'0'; blen=pos;
ANSlen=Alen>Blen?Alen:Blen;
anslen=alen>blen?alen:blen;
}
void my_strrev( char str[] )
{
char *p1=str;
char *p2=str+strlen(str)-1;
char temp;
while( p1=0;i-- ) // do not only anslen, pay attention to -1
{
ans[i]=( a[i]+b[i]+pro )%10;
pro=( a[i]+b[i]+pro )/10;
if( flag ) // reverse position
{
if( ans[i]==0 ) anslen--; // == 0
else flag=0;
}
}
my_strrev(A); convert(A);
my_strrev(B); convert(B);
for( i=0;i<=ANSlen;i++ )
{
ANS[i]=( A[i]+B[i]+pro )%10;
pro=( A[i]+B[i]+pro )/10;
}
for( i=ANSlen; ANS[i]==0 && i>=1;i-- );
for( ;i>=0;i-- ) printf("%d",ANS[i]);
printf(".");
for( i=0;i