Thursday, 30 August 2012

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 86932 then the output should be displayed as 97043.


main()
{
long num,a,b,c,d,e,new;
clrscr();
printf("Enter a five digit number\n");
scanf("%ld",&num);
a=((num%10)+1)%10;
e=num/10;
b=((e%10)+1)%10;
e=e/10;
c=((e%10)+1)%10;
e=e/10;
d=((e%10)+1)%10;
e=((e/10)+1)%10;
new=10000*e+1000*d+100*c+10*b+1*a;
printf("Result is %ld",num,new);
}

output:-

2 comments:

  1. #include
    int main()
    {
    int a,b=0,c=0,d=0,e=0;
    printf("Enter te no: ");
    scanf("%d",&a);
    b=a;
    while(b>0)
    {
    b=b/10;
    ++c;
    }
    printf("No. of digits %d ",c);
    while(c!=0)
    {
    d=d*10+1;
    c--;
    }
    e=a+d;
    printf(" %d",e);

    getch();
    }

    ReplyDelete