# include # include # include # include # include # using namespace std; # # include "middle_square.hpp" int main ( ); void middle_square_next_test ( ); void timestamp ( ); //****************************************************************************80 int main ( ) //****************************************************************************80 // // Purpose: // // middle_square_test() tests middle_square(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 16 September 2022 // // Author: // // John Burkardt // { timestamp ( ); cout << "\n"; cout << "middle_square_test():\n"; cout << " C version\n"; cout << " Test middle_square()\n"; middle_square_next_test ( ); // // Terminate. // cout << "\n"; cout << "middle_square_test():\n"; cout << " Normal end of execution.\n"; cout << "\n"; timestamp ( ); return 0; } //****************************************************************************80 void middle_square_next_test ( ) //****************************************************************************80 // // Purpose: // // middle_square_next_test() tests middle_square_next(). // // Discussion: // // This function simply demonstrates the results of 10 successive calls // to middle_square_next(), for a range of values of d. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 16 September 2022 // // Author: // // John Burkardt // { long long int d; long long int divisor; long long int i; long long int s; cout << "\n"; cout << "middle_square_next_test():\n"; cout << " middle_square_next ( s, d ) applies the middle square algorithm\n"; cout << " using a 2*d digit seed.\n"; for ( d = 1; d <= 5; d++ ) { cout << "\n"; cout << " Using d = " << d << "\n"; cout << "\n"; divisor = ( long long int ) pow ( 10, 2 * d ); s = ( 2147483647 % divisor ); for ( i = 0; i <= 10; i++ ) { cout << " " << i << " " << s << "\n"; s = middle_square_next ( s, d ); } } return; } //****************************************************************************80 void timestamp ( ) //****************************************************************************80 // // Purpose: // // timestamp() prints the current YMDHMS date as a time stamp. // // Example: // // 31 May 2001 09:45:54 AM // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 19 March 2018 // // Author: // // John Burkardt // { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct std::tm *tm_ptr; std::time_t now; now = std::time ( NULL ); tm_ptr = std::localtime ( &now ); std::strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm_ptr ); std::cout << time_buffer << "\n"; return; # undef TIME_SIZE }