Write a C++ program to read a positive integer greater than 0, the program should compute and display the following:
- Sum of odd digits in the number
- Count of even digits in the number
- The smallest digit.
For example, if the input is 24536, then
Sum of odd digits in the number = 8
Count of even digits in the number = 3
Smallest digit = 2
#include <iostream> using namespace std; int main() { int n, evens = 0, odds = 0, smallest = 9, d; cout << "Enter a positive integer: "; cin >> n; while (n > 0) { d = n % 10; n /= 10; if (d < smallest) smallest = d; if (d % 2 == 0) evens++; else odds += d; } cout << "Sum of odd digits in the number = " << odds << endl; cout << "Count of even digits in the number = " << evens << endl; cout << "Smallest digit = " << smallest << endl; return 0; }
Get Answers For Free
Most questions answered within 1 hours.