我已经把第一个题写出来了,当然我不用UNION来写
#include <stdio.h>
#include <stdlib.h>
#define LONG 15 //精度
void Make(char *p);
void GetString(char *p);
void Compute(int *sum,char *number1,char *number2);
void main()
{
char string1[LONG];
char string2[LONG];
int temp;
int sum[LONG-1];
GetString(string1);
GetString(string2);
Make(string1);
Make(string2);
Compute(sum,string1,string2);
printf("The result is:");
for(temp=0;temp<LONG-1;temp++)
{
if(sum[temp]!=0)
printf("%d",sum[temp]);
}
printf("\n");
}
void Make(char *p){
int i,j;
for(i=0;p[i]>47;i++){
}
for(j=LONG-1;j>=0;j--,i--){
if(i<0){
p[j]=48;
}
else
p[j]=p[i];
}
}
void GetString(char *p){
printf("please input number2:");
for(int temp=0;temp<LONG-1;temp++){
scanf("%c",&p[temp]);
if(p[temp]<=47){
p[temp]=0;
break;
}
}
}
void Compute(int *sum,char *number1,char *number2){
int i[LONG-1],j[LONG-1];
for(int temp=0;temp<LONG-1;temp++){
i[temp]=number1[temp]-48;
j[temp]=number2[temp]-48;
sum[temp]=(i[temp]+j[temp])%10;
sum[temp-1]=sum[temp-1]+(i[temp]+j[temp])/10;
}
}