编程计算1+2+4+5+7+8+10+11+13+14+16+17的值
编程计算1+2+4+5+7+8+10+11+13+14+16+17的值
1 4 7 10 13 16
2 5 8 11 14 17
程序代码:
#include <stdio.h>
#define 順加法(初, 結) ((初) == (結) ? ((初) + (結)) : (((結) > (初) ? (結) * ((結) + 1) - (初) * ((初) - 1) : (初) * ((初) + 1) - (結) * ((結) - 1)) / 2))
#define 順減法(初, 結) ((初) == (結) ? 0 : (((初) - (結) == 1) ? 1 : (((結) - (初)) == 1 ? 1 : (((結) > (初)) ? ((初) - 順加法((初) + 1, (結))) : ((初) - 順加法((初) - 1, (結)))))))
int main()
{
printf("%d\n", 順減法(10, 20));
return 0;
}