+ 1
How to answer this question?
Let assume that the user will enter 2134 as input ; your program will have to get first digit and last digit of the number and then take the product of them .
6 Antworten
+ 2
Have you tried to solve it ?
+ 2
Where is your attempt ? Share it so we can help you
+ 1
yes , but i couldn’t
+ 1
If the user only ever input a 4 digit number then:
have a look at what modulo (%) does e.g 4311%10 and 4321%100 and see if you can work out what else you need to do (can be done as a one liner) , if number can be any length you can do multiple if else but...might be easier to convert the number to a string.....use....>. to_string, use > substr then use > stoi...then add (or whatever) them.
look in here:-
http://www.cplusplus.com/reference/string/string/
edit:- you only need to_string if number is an int (depending on what type you declare the variable in the first place.
+ 1
thanks ❤️