Array plus

Implement the plusplus operator when we are getting the input as integer array = { 9,9,9,9 }.output will be {1,0,0,0,0}

C++:
01 void arrayPlus(int A[], int size, int& len)
02 {
03     int i=len1;
04     while((A[i]==9)&&(i>=0)){
05             A[i+1]=0;
06             i;
07     }
08     if(i==-1){
09         len++;
10         A[0]=1;
11     }else{
12         A[i]++;
13         for(int j=i+1;j<len;j++)
14             A[j]=A[j+1];
15     }
16 }
Advertisements
This entry was posted in Array and linked list. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s