- #include "stdio.h"
- #include "string.h"
- void add(char *d1, char *d2, char *out);
- int main(int argc, char *argv[])
- {
- if (argc < 3)
- {
- printf("error \\n");
- return 0;
- }
- char result[1024] = {0,};
- char * c1 = strlen(argv[1]) > strlen(argv[2]) ?argv[1] : argv[2];
- char * c2 = strlen(argv[1]) <= strlen(argv[2]) ?argv[1] : argv[2];
- add(c2,c1,result);
- printf("%s \\n",result);
- return 0;
- }
- void add(char *d1, char *d2, char *out)
- {
- int len_min = strlen(d1);
- int len_max = strlen(d2);
- int last_j = 0;
- while(len_min > 0)
- {
- int x = (d1[len_min - 1] -'0') + (d2[len_max - 1] - '0');
- if (last_j) x = x + 1;
- out[len_max] = (x % 10) + '0';
- last_j = ((x / 10 ) == 1);
- len_max -- ;
- len_min -- ;
- }
- while(len_max > 0)
- {
- int x = (d2[len_max -1] - '0');
- if (last_j) x = x + 1;
- out[len_max] = (x % 10) + '0';
- last_j = ((x / 10 ) == 1);
- len_max --;
- }
- if (last_j)
- out[0] ='1';
- else
- out[0] ='0';
- }
- void cef(char *d1, char *d2, char *out)
- {
- }
- void chf(char *d1, char *d2, char *out)
- {
- int len_min_x = strlen(d1);
- int len_max_y = strlen(d2);
- //1 - len_max_y
- char tempout[1024] = {0,};
- while(1)
- {
- //x* (y / 2) - y
- //如果当前值与 y 的差 小于 x
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/150520133380.html
来源: http://www.codesnippet.cn/detail/150520133380.html