Answer:
C++ code is explained
Step-by-step explanation:
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int firstDigit(int n){
// Converting int to string
ostringstream convert;
convert << n;
string s = convert.str();
char first_char = s[0];
int first_int = first_char - '0';
return first_int;
}
int lastDigit(int n){
// Converting int to string
ostringstream convert;
convert << n;
string s = convert.str();
char last_char = s[s.length() - 1];
int last_int = last_char - '0';
return last_int;
}
int digits(int n){
// Converting int to string
ostringstream convert;
convert << n;
string s = convert.str();
int length = s.length();
return length;
}
int main() {
int number;
cout << "Enter integer: " << endl;
cin >> number;
cout << "The first digit of the number is " << firstDigit(number) << endl;
cout << "The last digit of the number is " << lastDigit(number) << endl;
cout << "The number of digits of the number is " << digits(number) << endl;
}