Scanning every digit of a number and increment every digit by value 1...help

Think,an int a=2348;
so the desired output should be 3458…
I tried to print out the last digit by this logic

int lastdigit(a){
int m=0;
for(int k=0;k<=9;k++)
{
m=a-k;
if(m%10==0)
return k;

}

return 0;

}

But i couldn’t use this idea successfully to get the upper limit digits…
Thanks.

Using the same logic

U can repeat the usage of “last digit(a)” several times, dividing by 10 every time.

The code would be:

int a=2348;
while(a!=0)
{
      int d=lastdigit(a);
      a/=10;
}
1 Like
//