0% found this document useful (0 votes)
5 views1 page

Digit Toolbox Cheatsheet

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Digit Toolbox Cheatsheet

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Digit Toolbox Cheatsheet (C++)

1. Last Digit: last = no % 10;


→ Gets the last digit directly.

2. First Digit: while(no >= 10) no /= 10; first = no;


→ Keep dividing until only one digit remains.

3. Count Digits: count=0; while(no!=0){ no/=10; count++; }


→ Each chop counts one digit.

4. Sum of Digits: sum=0; while(no!=0){ sum+=no%10; no/=10; }


→ Add all digits together.

5. Product of Digits: product=1; while(no!=0){ product*=no%10; no/=10; }


→ Multiply all digits together.

6. Reverse Number: rev=0; while(no!=0){ rev=rev*10+(no%10); no/=10; }


→ Reverses the number digit by digit.

7. Palindrome Check: if(no == rev) cout << "Palindrome";


→ Number is same forward and backward.

8. Count Even/Odd Digits: if((no%10)%2==0) even++; else odd++;


→ Classify digits as even or odd.

Your quick reference for digit problems in C++

You might also like