// Functions can call themselves. // This is called recursion. #include #include using namespace std; int triangular_number( int n ) { if ( n == 1 ) return( 1 ); else return( n + triangular_number( n-1 ) ); // Functions calls itself! } int main() { char choice; int n; do { cout << "Enter a positive integer: "; cin >> n; cout << "T(" << n << ") = " << triangular_number( n ) << endl; cout << "Run again? (y=yes) "; cin >> choice; } while( choice == 'y' || choice == 'Y' ); cout << "\n\n"; system( "PAUSE" ); return( EXIT_SUCCESS ); }