Error

-1 Satan's Mayhem · September 25, 2014
input A[n=5]=1,2,3,4,5
 
Required output=5,1,2,3,4

Output that i'm getting 5,1,1,1,1   >_< >_<  >_<
WHY?

int temp=A[n-1];

for(int q=0;q<n-1;q++)
{
A[q+1]=A[q];
}

A[0]=temp;
}

Post a Reply

Replies

Oldest  Newest  Rating
0 Satan's Mayhem · September 25, 2014
Got that :)
Thanks
+1 Pere Garau Burguera · September 25, 2014
The first time you go into the loop, you do a[1]  = a[0]
That means that the second number is now equal to the first, which is 1.
Then you go into the loop again, and you have a[2] = a[1]
a[1] is now 1 because you changed it the first time you did the loop, so a[2] = 1
Then a[3] = a[2], a[4] = a[3] they will all be one
  • 1

Java / Android Development

124,304 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator