can any one help me with code that subtract 1 from a digit stored in an array using c++ (elementary mathematics) eg.. 100-1=99 and 98-1=97
A:
If you have stored the digits in an array, you'll need to follow your elementary-school math on the array from right to left. "Borrow" from the next place to the left as needed.
jheddings
2009-11-03 19:20:09
Please don't do their homework for them. Just give them enough to be able to think it through themselves. If you give them all the answers, they don't learn anything and we end up with lots of bad code to fix and maintain later.
Ken White
2009-11-03 19:30:21
thanx but not this one for example i have the nuber 9999870 whose digits are stored in array i want to subtract 1 from this number which will give 9999869 using elementary mathmatics
prateek
2009-11-03 19:32:28
Sorry, didn't realize it was homework... It doesn't seem like that constitutes a down vote.
jheddings
2009-11-03 19:35:35
@jheddings: I didn't downvote you. I just made the suggestion about not providing homework answers.
Ken White
2009-11-03 19:49:22
No worries, not sure who did (doesn't really matter). I was just trying to understand why it was down-voted.
jheddings
2009-11-03 20:02:37
A:
Sounds like a homework, so I could only give you helpful links.
Here you could read about C++ array. And here about transform algorithm that can do the job.
Kirill V. Lyadvinsky
2009-11-03 19:35:51