
Patrick B. answered 06/06/21
Math and computer tutor/teacher
using namespace std;
#include <iostream>
#include <stdio.h>
//method #1: using standard and modular division
DigitsV1(int x)
{
int iTens = x%100;
cout << " The hundreds place is " << x/100 << endl;
cout << " The tens place is " << iTens/10 << endl;
cout << " THe ones place is "<< iTens%10 << endl;
}
//method #2: using a string
DigitsV2(int x)
{
char buff[25];
sprintf(buff,"%d",x);
cout << "The hundreds place is " << buff[0] << endl;
cout << "The tens place is " << buff[1] << endl;
cout << "the ones place is " << buff[2] << endl;
}
Go()
{
int iNum=0;
cout << "Please input the 3-digit number :> ";
cin >> iNum;
DigitsV1(iNum);
cout << "--------------------------------------" << endl;
DigitsV2(iNum);
}
main() { Go(); }