+ 2
Accept 'n' values in an array and print the first and last digit of each element present in the array.
I cannot get the desired output and I am not able to detect my mistake. Though the program code is correct but it is not giving the output as when i enter a three digit number as input in the array, it did not give me the desired first digit of that number itself. Plz can someone help me in this. I would be grateful. Here is the code i have done! ! ! https://code.sololearn.com/c540NQUswWs4/?ref=app
6 Antworten
+ 5
1) condition in else if will only be evaluated when condition inside *if* statement is FALSE which is not the case for any number greater than 9 (as mentioned by Ruba Kh )
2) your code will not work for number greater than 999 like this.( you should preffer another method to find out first digit of the number)
here is the fix👇
https://code.sololearn.com/cVz2MSABv55l/?ref=app
+ 2
The problem in your code is that it will enter the first if condition if number is greater than 9 so even if it is greater than 99 it will still enter the first if
For example 203 is greater than 9 so it will enter the first if
+ 2
Ruba Kh
Yes i have understood and thank you for your help.
+ 2
Arsenic Thanks a lot for your great concern.I am thankful to you.
+ 1
Plz help me in this!!
I would appreciate your effort!!!
+ 1
So if you modify the first if like this
if(a[i]>9 && a[i]<=99)
it will work