C++ Program: Recursion -Recursive function that Finds the sum of digits

preview_player
Показать описание
Simple c++ program that uses recursion to find the sum of the digits entered

Рекомендации по теме
Комментарии
Автор

what a great way to explain something confusing like Recursion
definitely I will be checking your other videos as well
thanks

_RahmaF
Автор

how can i open the program i did every thing like u but in the end it didnt open the black CMD THING

iiimtw
Автор

thats what i did



//sum of digits recursion
#include <iostream>
using namespace std;
int sumofdigits(int x){
if(x<10) return x; //base case
return sumofdigits(x/10)+x%10;

}
int main(){
in x;
cout << "enter a #: " <<endl;
cin>> x;
cout << sumofdigits(x)
return 0;
}

iiimtw