Sum of digits in c or c++ without pointers

1–2 minutes

read

Sum of digits in c or c++ without pointers

 

Screen Shot 2017-08-16 at 1.30.35 PM

SO, the main logic behind this is=:

b = a%10; // we took the remainder after dividing by 10 thats the last digit

sum = sum+ (b*c); // adding last digit to sum

a = a/10; //to remove last digit from a

c= c/10; //to remove last digit from a

and in last we will return sum.

Leave a comment