Thu Feb 06 2025 05:09:43 GMT+0000 (Coordinated Universal Time)
Saved by @Rohan@99
#include <iostream> using namespace std; int sumOfDigits = 0; void SumOfDigits(int n){ if(n%10 == 0){ cout << sumOfDigits; return; } sumOfDigits += n%10; n /= 10; SumOfDigits(n); } int main() { int n; cin >> n; SumOfDigits(n); return 0; }
Copy this HTML code:
Preview:
open_in_newInstructions on embedding in Medium
Comments