In this program, we have to check whether a string consists of only digits (i.e. 0,1,2.....9). eg:- "qwerty" ( the given string contains characters, not digits ) print No. "123e" ( there is a character present in the given string ) print No. "995765" (the given string contains only digits, no any characters are present ) print Yes. How to approach :- Traverse through each character of the string and for each character check whether it is a digit or not. Now the question is " How to check a character in the given string is alphabet or digit ? " We can check this by 2 methods :-- 1. Check using ASCII value:-- If the ASCII value of a character is between 48 to 57 (including both 48 and 57) then it is a digit (0,1,2,3,....,8,9). If the ASCII value of a character is between 65 to 90 (including both 65 and 90) then it is a uppercase alphabet (A,B,C,D,....,Y,Z)....
This blog contains coding/programming and interview questions of MNCs like TCS, Wipro, Infosys, Capgemini, Mindtree, Amazon, Google, Facebook, Flipkart, Cisco, HP, Dell, etc. with placement preparation guides.