# C Program to Increment by 1 to all the Digits of a Given Integer

«
»

This is a C program to Increase 1 to all of the given Integer Digit.

Problem Description

This program increases 1 to all of the given integer digit and print the sum of all digits.

Problem Solution

1. Take a integer as input.
2. Obtain its remainder and quotient.
3. Increment the remainder by 1 and add to the another variable.
4. Repeat the steps 2 & 3 with the quotient obtained until the quotient becomes zero.

Program/Source Code

Here is source code of the C Program to Increase 1 to all of the given Integer Digit and print the sum of all digits. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

1. ` `
2. `/*`
3. ` * C program to Increase 1 to all of the given Integer Digit`
4. ` */`
5. `#include <stdio.h>`
6. ` `
7. `int main()`
8. `{`
9. `    int number, sum = 0, remainder, count;`
10. ` `
11. `    printf("Enter a number: ");`
12. `    scanf("%d", &number);`
13. `    while (number)`
14. `    {`
15. `        remainder = number % 10;`
16. `        sum  = sum + (remainder + 1);`
17. `        number /= 10;`
18. `    }`
19. `    printf("increasing 1 to all digits:  %d", sum);`
20. `    return 0;`
21. `}`
Program Explanation

1. Initialize variable sum to zero.
2. Take a number as input and store it in the variable number.
3. Obtain the remainder and quotient of the variable number. Store the remainder in the variable remainder and override the variable number by quotient.
4. Increment the variable remainder by 1 and add it to the variable sum.
5. Repeat the step 3 & 4 with the quotient obtained until it becomes zero.
6. When it becomes zero, print the variable sum as output and exit.

Note: Join free Sanfoundry classes at Telegram or Youtube
Runtime Test Cases
```Enter a number: 3456
increasing 1 to all digits:  22```

Sanfoundry Global Education & Learning Series – 1000 C Programs.

Here’s the list of Best Books in C Programming, Data-Structures and Algorithms

If you wish to look at other example programs on Simple C Programs, go to Simple C Programs. If you wish to look at programming examples on all topics, go to C Programming Examples. 