C++ Program to find the sum of odd digits of a number
Here you get the example code to find the sum of odd digits of a number in C++ programming.
For Example:-
1 2 3 | Numbers => 1234567 Result => 1 + 3 + 5 + 7 = 16 |
Example to find the sum of odd digits of a number in C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include <iostream.h> using namespace std; int main() { long int num,rem=0,sum=0; cout << "\n\nEnter a number : "; cin >>num; while (num > 0) { rem = num % 10; if(rem % 2 != 0) { sum=sum+rem; } num = num / 10; } cout << "\n\nSum of Odd digits of Number:" << sum; return 0; } |
Output
Enter a number : 12345
Sum of Odd digits of Number : 9
Check out our other C++ programming Examples