By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,573 Members | 903 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,573 IT Pros & Developers. It's quick & easy.

how to carry the tenth place number of the elements while adding 2 arrays?

P: 1
for example, input the values of a and b where they are arrays taking input of 4 values.
a=[0 4 5 6]
b=[0 6 6 5]
sum=[1 1 2 1]
Mar 23 '19 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 1,035
Define an extra variable (i.e. 'c') which you init with zero (0)

Do not add a+c, but add a+b+c

Assign c with the overflow of this addition.

So,
5 + 6 + 0 = 11 ==> output 1, and assign 1 to 'c'
5 + 6 + 1 = 12 ==> ourput 2, and assing 1 to 'c'
4 + 6 + 1 = 11 ==> output 1, and assign 1 to 'c'
0 + 0 + 1 = 1 ==> output 1, and assign 0 to 'c'
Mar 23 '19 #2

dev7060
100+
P: 113
- Use the modulus operator to extract the ones place like

(a+b+c)%10=sum[index]

- Use the division operator to get the next value of c

c=(a+b+c)/10
Mar 26 '19 #3

Post your reply

Sign in to post your reply or Sign up for a free account.