write a program in Java to input a number and calculate its sum of alternative number
please tell the ans fast it's necessary please
Answers
Answered by
0
Answer:
for your exam
Explanation:
Examples :
Input : n = 687
Output : 21
Input : n = 12
Output : 3
Recommended: Please solve it on “PRACTICE ” first, before moving on to the solution.
General Algorithm for sum of digits in a given number:
Get the number
Declare a variable to store the sum and set it to 0
Repeat the next two steps till the number is not 0
Get the rightmost digit of the number with help of remainder ‘%’ operator by dividing it with 10 and add it to sum.
Divide the number by 10 with help of ‘/’ operator
Print or return the sum
Below are the solutions to get sum of the digits.
1. Iterative:
Similar questions
English,
3 months ago
Business Studies,
3 months ago
History,
3 months ago
Math,
7 months ago
Computer Science,
1 year ago
Social Sciences,
1 year ago
English,
1 year ago