tags:

views:

140

answers:

2

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
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
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
Sorry, didn't realize it was homework... It doesn't seem like that constitutes a down vote.
jheddings
@jheddings: I didn't downvote you. I just made the suggestion about not providing homework answers.
Ken White
No worries, not sure who did (doesn't really matter). I was just trying to understand why it was down-voted.
jheddings
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