1、题目
一个数m的连续整数固定和就是指存在a1,a2,…an,后一个数只比前一个数大一,而且它们的和等于数m。
2、分析
最直观解法就是穷举法
3、源码
1: #include <stdio.h>
2:
3: void cntnsIntSum(int n)
4: {
5: int i, sum = 0, j;
6:
7: for(i = 1; i < n; i++)
8: {
9: j = i - 1;
10:
11: while(sum < n)
12: {
13: j++;
14: sum = sum + j;
15: }
16:
17: if(sum == n)
18: {
19: printf("%d+...+%d = %d\n", i, j, n);
20:
21: }
22:
23: sum = 0;
24: }
25: }
26:
27: int main()
28: {
29: int n;
30: printf("Please input a integer\n");
31: scanf("%d", &n);
32: cntnsIntSum(n);
33: return 0;
34: }