Radical Developers welcomes all the visitors to be a member of the team. Come join us. Its all about open-source concept. All Programs are written and tested in MacOS X, Unix, Linux and may not match with the outputs of Turbo C++ in Windows

Sunday, January 9, 2011

If a 5-digit number is input through the keyboard. Write a program to print a new number by adding one to each of its digits. E.g. If the no. that is 12391, then the output should be displayed as 23402.


Source Code :

#include<stdio.h>
void main()
{
      int m,i,j,n,r=0,c;
      clrscr();
      printf("Enter a 5-digit number : ");
      scanf("%d",&m);
      for(i=1;i<=5;i++)
      {
            c=1;
            n=m%10;
            m=m/10;
            for(j=1;j<i;j++)
            {
                  c*=10;
            }
            n++;
            if(n==10)
                  r=r+(c*0);
            else
                  r=r+(c*n);
      }
      printf("\nRequired Output : %d",r);
      getch();
}

Output :

Enter a 5-digit number : 12391

Required Output : 23402

No comments:

Post a Comment