3197, the third last digit is 1.
Note 1 - The third last digit should be printed as a positive number. i.e. if the given number is -197, the third last digit is 1.
Note 2 - If the given number is a single-digit or double-digit number, then the third last digit does not exist. In such cases, the program should print -1. i.e. if the given number is 5, the third last digit should be print as -1.
#include <iostream>
using namespace std;
int main()
{
int n,digit;
cin>>n;
if (sizeof(n) < 3)
{
cout<<"-1";
}
else
{
n = n / 100;
digit = n % 10;
}
cout<<" the third last digit found:";
cout<<digit;
return 0;
}
Comments
Leave a comment