// nextPerfect(n) returns the smallest perfect // number that is larger than n. int nextPerfect(int n) { int k = n+1; while(!isPerfect(k)) { k++; } return k; }