Answer to Question #174172 in C++ for Sharath kumar

Question #174172

the given number.

For example, if the given number is 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.


1
Expert's answer
2021-03-22T05:58:37-0400
using namespace std;


main(void)
{
	string Num;
	char n=-1;	
	cout<<"\nEnter the number: "; 	cin>>Num;//scanf("%[^\n]",Num);	
	if(Num.length()<=2) 	n = -1;
	else					n = Num[Num.length()-3];
	cout<<"\n\nThe 3rd last digit: "<<n;
	return(0);
}




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS