#include <stdio.h>
#include <math.h>
int length(int arr[], int len) {
int i;
for(i = len-1; i >= 0; i--) {
if(arr[i]) {
return i + 1;
}
}
return len;
}
void main() {
/*
加法运算
*/
int nums1[10] = {2, 2, 2};
int nums2[10] = {9, 8, 7};
int carry = 0;
int i, n, count = 1, result = 0;
int len = sizeof nums1 / sizeof nums1[0];
for(i = length(nums1, len) - 1; i >= 0; i--) {
n = nums1[i] + nums2[i] + carry;
carry = floor( n/10 );
if(count == 1) {
result = result + n % 10;
count *= 10;
continue;
}
result = result + n % 10 * count;
count *= 10;
}
if( carry ) result += count;
printf("%d\n", result);
}
标签:count,10,求和,len,int,result,数组,长度,nums1
From: https://www.cnblogs.com/anas-kai/p/17040517.html