mirror of
https://github.com/VictorEijkhout/TheArtOfHPC_vol3_cppf08programming.git
synced 2026-01-24 22:44:48 +09:00
36 lines
888 B
C++
36 lines
888 B
C++
/****************************************************************
|
|
****
|
|
**** This file belongs with the course
|
|
**** Introduction to Scientific Programming in C++/Fortran2003
|
|
**** copyright 2016-2021 Victor Eijkhout eijkhout@tacc.utexas.edu
|
|
****
|
|
**** mult.cxx : recursive multiplication
|
|
****
|
|
****************************************************************/
|
|
|
|
#include <iostream>
|
|
using std::cin;
|
|
using std::cout;
|
|
|
|
//codesnippet multrecur
|
|
int times( int number,int mult ) {
|
|
cout << "(" << mult << ")";
|
|
if (mult==1)
|
|
return number;
|
|
else
|
|
return number + times(number,mult-1);
|
|
}
|
|
//codesnippet end
|
|
|
|
int main() {
|
|
|
|
int number,multiplier;
|
|
cout << "Enter number and multiplier" << '\n';
|
|
cin >> number; cin >> multiplier;
|
|
cout << "recursive multiplication\n of "
|
|
<< number << " and " << multiplier << ": "
|
|
<< times(number,multiplier) << '\n';
|
|
|
|
return 0;
|
|
}
|