// Solution of Assignment 8.
#include <iostream>
#include <string>
using namespace std;

void find(int,int&,int&,int&);

int main()
{
	int n, count, sum, max;
	cout << "Enter an integer: ";
	cin >> n;
	find(n,count, sum, max);
	cout << "\n\t\tNumber of digits: " << count << endl;
	cout << "\t\tSum of digits: " << sum << endl;
	cout << "\t\tMaximum digit: " << max << endl << endl;
	system("pause");
	return 0;
}

void find(int n, int& count, int& sum, int& max)
{
	int m;
	n = abs(n);
	sum = 0;

	// If n = 0 initialize count to 1; otherwise 
	// initialize count to 0.
	count = (n == 0)? 1: 0;

	// If n = 0 initialize max to 0; otherwise 
	// initialize max to -1.
	max = (n == 0)? 0: -1;

	while (n != 0)
	{
		// Get the first digit from the right
		m = n % 10;

		if (m > max)
			max = m;
		sum += m;
		count++;

		// Remove the first digit from the right
		n = n / 10;
	}
}
