+ 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 .

20th Oct 2019, 9:16 PM
Rhim Khalid
6 Respostas
+ 2
Have you tried to solve it ?
20th Oct 2019, 9:18 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 2
Where is your attempt ? Share it so we can help you
20th Oct 2019, 9:32 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 1
yes , but i couldn’t
20th Oct 2019, 9:27 PM
Rhim Khalid
+ 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.
20th Oct 2019, 10:03 PM
rodwynnejones
rodwynnejones - avatar
+ 1
thanks ❤️
20th Oct 2019, 10:05 PM
Rhim Khalid