整数划分(计数+划分显示)

#include <cstdlib> #include <iostream> using namespace std; const int MAX = 100; int fac[MAX] = {0}; int sum(int count) { int sum = 0; for(int i=0; i<=count; i++) sum += fac[i]; return sum; } void display(int count, int value) { if(count == 0) cout << value << " + " << "0" << endl; else { for(int i=0; i<count; i++) cout << fac[i] << " + "; cout << fac[count] << endl; } } int division(int begin, int count, int value) { static int count1 = 0; for(int i=begin; i>0; i--) { fac[count] = i; if(value == sum(count)) { display(count, value); count1++; } else if(value < sum(count)) continue; if(count >= value) continue; division(i, count + 1, value); } return count1; } int main(int argc, char *argv[]) { int value; cout << "please input a value: "; cin >>value; cout << "division count is: " << division(value, 0, value) << endl; system("PAUSE"); return EXIT_SUCCESS; }  

你可能感兴趣的:(System,input,include)