if 5 digit number is input through kryboard , then wap to print a new number by adding one to each digit . for example if the input is 12391 then output should be 23402.(loop)



 



#include<stdio.h>
#include<conio.h>
 main()
{
   int n,r,add=0,rev=0;


   printf("Please enter any  number ");
   scanf("%d",&n);

     while(n>0)
     {
       r=n%10;
       n=n/10;
       rev=rev*10+r;
     }

     while(rev>0)
     {
       r=rev%10;
       rev=rev/10;
       r=r+1;
r=r%10;
       add=add*10+r;
     }

    printf("%d",add);


}

output :
Please enter any number 345678 456789

Comments

Popular Post

Create a base class called shape .Use this class to store two double type values that could be used to compute the area of figures, Derive two specific classes called triangle and rectangle from the base shape .Add to the base class, a member function get_data() to initialise base class data members and another member function display_area() to compute and display the area of figures. Make display_area () as a virtual function and redefine this function in the derived class to suit their requirements. Using these three classes, design a program that will accept dimensions of a triangle or a rectangle interactively and display the area. Area of rectangle = x*y Area of triangle = ½*x*y