+ 1

# Can anyone help me to understand this code?

#include <stdio.h> int main () {int x= 123; int sum= 0; while(x>0) { sum+= x%10; x = (x - x%10)/10; } printf("%d",sum); } It's output is 6.

3 Answers

+ 4

This code will seprate the Entered number one by one adn sum +=x/10 will add all sepratated numbers write one copy how values changing you will understood.
If you divide any Number by 10 then you will get last number as a Remainder

+ 2

Put value and calculate how Values varying

0

🗡️Jasprit What x = (x-x%10)/10 will do?