Write an algorithm that determines whether the sum of the digits of N, a three-digit number, is odd or even.
So like if N was 324, it would see if the result of 3+2+4 was odd or even
Answers
Answered by
0
Explanation:
Input : n = 687
Output : 21
Input : n = 12
Output : 3
// C program to compute sum of digits in
// number.
# include<iostream>
using namespace std;
/* Function to get sum of digits */
class gfg
{
public:
int getSum(int n)
{
int sum = 0;
while (n != 0)
{
sum = sum + n % 10;
n = n/10;
}
return sum;
}
};
//driver code
int main()
{
gfg g;
int n = 687;
cout<< g.getSum(n);
return 0;
}
//This code is contributed by Soumik
Similar questions