From: http://blog.csdn.net/ndzjx/article
#include <iostream> using namespace std; int nCount = 10; int nBegin = 5; int nEnd = nBegin + nCount; int narr[25] = { 1, 13, 3, 5, 8, 9, 2, 4, 13, 22, 44, 23, 7, 9, 0, 32, 13, 12, 6, 15, 14, 21, 16, 18, 4}; intmain() { // I want to change the following for to the above for, thinking it is simpler, // Actually, it's not right (the data source analyzed is large, and the results obtained have increased) // Remember: refactoring must write a test applet! Thoughts can deceive people, programs do not. for (int i = 0; i < 25; ++i) { int nValue = narr[i]; if (nValue < nBegin || nValue >= nEnd) { cout << nValue << endl; } } for (int i = nBegin; i < nEnd; ++i) { bool bFlag = false; for (int j = 0; j < 25; ++j) { if (narr[j] == i) { bFlag = true; break; } } if (!bFlag) { cout << i << endl; } } return 0; }