Tuesday, 24 December 2013

If a five-digit number is input through the keyboard, write an algorithm 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 23402.(c++ code)

#include<iostream>
using namespace std;
#include<conio.h>
int main ()
{
int i,temp = 0;
cout<<"Enter a +ve 5 digit number :";
cin>>i;
if (( i <= 99999 ) && ( i > 9999 ))
{
cout<<(i/10000) + 1;
cout<<((( i/100) % 100)/10) + 1;
cout<<(( i/100) % 10 ) + 1;
cout<<((i % 100) / 10) + 1 ;
cout<<(i % 10) + 1;
}
else
cout<<"\n Pleas enter +ve five digit number";
getche();
return 0;
 

  /*  Letuswithc:

       this page is designed to help you learn C or C++.
  Understandable C and C++ programming tutorials, compiler reviews, source code, tips and tricks. 
         */
}

No comments:

Post a Comment