Program to find sum of digits until the number is a single digit. (Level- Medium)

Program # 12: find sum of digits until the number is a single digit

Program to find sum of digits until the number is a single digit.(Level- Medium)


#include <iostream>
using namespace std;

int main()
{
int number = 158;      //Any number.
int res;

if(number)
res = number % 9 == 0 ? 9 : number % 9 ;
else
res = 0;

//print the result
cout<<res;

return 0;
}

Post a Comment

0 Comments