C/C++ | 18-2 整数组合

来源:互联网 发布:python ampy 编辑:程序博客网 时间:2024/06/05 08:17
/*
2、输出和为一个给定整数的所有组合
例如n=5
5=1+4;5=2+3(相加的数不能重复)
则输出
1,4;2,3。

*/


需要继续分解。待续

#include <stdio.h>  #include <stdlib.h>#include <iostream>#include <string.h>#include <assert.h>using namespace std;int main(){int a, b, c;cin >> a ;if (a % 2 == 0){b = a / 2;}else{b = a / 2 + 1;}for (c = 1; c < b; c++){cout << a << "=" << c << "+" << a-c << ";" << endl;}system("pause");    return 0;}


原创粉丝点击