dimanche 25 novembre 2018

Adding specific digits with while loop in c++

Write a function in a program that reads a six-digit integer and prints the sum of its six digits. Use the quotient operator / and the remainder operator % to extract the digits from the integer. For example, if n is the integer 876,543, then n/1000%10 is its thousands digit 6.

Can anyone give me the logic behind this question. It must use while loop and should only find sum of 6 digits. For example if an user enters 111111 it should return 7. It shouldn't find sum of any number lower or highr than 6 digits

Aucun commentaire:

Enregistrer un commentaire