Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

c program to add 1 to each digit of a number

#include <stdio.h>

int main(void)
{
    int num, sum, remainder, check; // check used as a boolean expression
    sum = check = 0;

    printf("Enter the sequence: ");
    scanf("%d", &num);

    while (num > 0)
    {
        remainder = num % 10; // each time num is reduced

        if (remainder != 9)
        {
            if (check == 0)
                sum = (10 * sum) + (remainder + 1);
            else
            {
                sum = (10 * sum) + (remainder + 2);
                check = 0;
            }
        }
        else
        {
            sum = (10 * sum) + 0;
            check = 1;
        }
        num /= 10; // will divide and execute in each iteration until it's true
    }

    num = sum; // final number will be equal to the sum
    sum = 0;

    // Summing up the results
    while (num > 0)
    {
        remainder = num % 10;
        sum = (10 * sum) + remainder;
        num /= 10;
    }

    printf("Result: %d
", sum);

    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Shell :: Git - switch to specific branch (ex: "feature") 
Shell :: install ros on docker 
Shell :: see prerouting rules linux 
Shell :: Send iMessage From Command Line With Bash/Osascript (Osascript = Command Line Version Of Applescript) 
Shell :: cmd create fgile 
Shell :: deleting when you terminate it 
Shell :: vscode find all @media 
Shell :: git add symlink 
Shell :: Install the package to configure and build kernel 
Shell :: terminal grep get line with length 
Shell :: The zip extension must be loaded 
Shell :: cargo create 
Shell :: go back to a folder in git 
Shell :: update pulumi 
Shell :: picoCTF file-run1 
Shell :: powershell cat equivalent 
Shell :: i want to merge head with master in git 
Shell :: zsh prompt losing customization when using `sudo su` 
Shell :: figma edge 
Shell :: set up monitor refresh rate from command line fedora 
Shell :: install rar, unrar on fedora 
Shell :: ubuntu uninstall google chrome 
Shell :: basic config palo alto cli 
Shell :: zsh: permiso denegado: /home/sebastian/.bash_aliases 
Shell :: install discord on a script 
Shell :: how to know the no of machines running on locust through unix 
Shell :: custom linux cursor, linux cursor, install Bibata 
Shell :: batch write to file 
Shell :: To exclude files with patterns containing preceding and trailing characters : 
Shell :: output text after specific character powershell 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =