Need help with c++ please. Thank you.
Write a program that displays the sum of all odd digits of an input.
Expert Answer
Program :
#include <iostream>
using namespace std;
int main()
{
int n,odd = 0;
cout<<“Enter a number :”;
cin >> n;
while(n > 0)
{
int digit = n % 10;//It gives last decimal digit
n /= 10;//it remove last digit from n
if(digit % 2 != 0) // If it is an odd digit
odd += digit; // add odd digits of n
}
cout<<“Sum of all odd digits of an input is “<<odd;
}
Output :