Once you understand how loops can be used to iterate your process life as a programmer getsĀ more simpler. There can be so many tricks played around if you can identify all the digits from a given number.

For example:

- Check whether the last digit is even or odd
- To print the sum of the digits
- To print the sum of even number digits used.
- Check if it starts with 98 and has total number of digits is exactly 10.
- Check if it is a palindrome, etc.

Similar logical solutions can be designed only if you will be able to successfully identify the digits.

### ALGORITHM:

**Step #1.** Read the number ( declare it ** long int** for large range coverage )

**Step #2**. Repeat until the last digit.Increase the counter variable

**Step #3.** Finally display the count.

### SOURCE CODE:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
/******************************************************** * This program counts the total number of digits * * of the number * * Created By: Dhiraj Jha * * Email: callmedhiraj[at]gmail.com * * Created Date: 9/14/2018 * ********************************************************/ #include<stdio.h> #include<conio.h> #include<stdlib.h> // main implementation int main(){ //declare the necessary variables. long int number; int digitCount = 0; //read the number from the user printf("Enter the number: "); scanf("%ld", &number); //iterate do{ digitCount++; //minimum single digit, so counter increased number= number / 10; // divide the number by 10 reduces it by 1 place from left }while(number % 10 != 0); // remainder by 10 checks if it is the last digit //finally print the total count printf("\n%d digits", digitCount); getch(); return 0; }//main ends |

## Leave a Reply

You must be logged in to post a comment.