Q5 If a five-digit number is input through the keyboard, write a program to print a new number by adding one to each of its digits. For example, if the number that is input is 12391, then the output should be displayed as 23502.

If a five-digit number is input through the keyboard, write a program to print a new number by adding one to each of its digits. For example, if the number that is input is 12391, then the output should be displayed as 23502.

Program: 68

If a five-digit number is input through the keyboard, write a program to print a new number by adding one to each of its digits. For example, if the number that is input is 12391, then the output should be displayed as 23502.

#include<stdio.h>
#include<conio.h>
int main()
{
    int num, sum, i, number, count=0, n=1;

    printf("Enter N Digit's Number: ");
    scanf("%d", &num);

    number = num;

    //get the counter till then we have to run the loop

    while(number!=0)
    {
        number = number/10;
        count = count + 1;
    }

    for(i=1;i<count;i++)
    {
        n = n * 10;  //n = 10
        n = n + 1;   //n = 11
    }

    sum = num + n;
    printf("Output: %d", sum);
}

Output

Enter N Digit's Number: 12349
Output: 23460
Lokesh Kumar: Being EASTER SCIENCE's founder, Lokesh Kumar wants to share his knowledge and ideas. His motive is "We assist you to choose the best", He believes in different thinking.

View Comments (4)

  • Logic is good but you can see your program at list once output of programe is not match as expected

  • the question says that when ever a digit 9 comes the number left side to it should not be increased by 2. that is happening in your program so, I think question is not same

  • #include <stdio.h>
    int main()

    {
    int num [5];

    printf("Enter the numbers: ");
    //while entering the number give space between them
    scanf("%d%d%d%d%d",&num[0],&num[1],&num[2],&num[3],&num[4]);

    num[0]=num[0]+1;
    num[1]=num[1]+1;
    num[2]=num[2]+1;
    num[3]=num[3]+1;
    num[4]=num[4]+1;

    printf("%d%d%d%d%d",num[0],num[1],num[2],num[3],num[4]);

    return 0;

    }

Related Post
Leave a Comment

This website uses cookies.