Advertisement
Shailrshah

Array Right-Shift

Apr 19th, 2013
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.54 KB | None | 0 0
  1. #include <stdio.h>
  2. int main()
  3. {
  4.     int a[100],i,n,temp;
  5.     printf("Enter the array's limit: ");
  6.     scanf("%d",&n);
  7.     printf("Now enter %d elements to fill the array.\n",n);
  8.     for(i=0; i<n; i++)
  9.         scanf("%d",&a[i]);
  10.     temp = a[n-1];
  11.     for(i=n-2;i>=0;i--)
  12.         a[i+1] = a[i];
  13.     a[0] = temp;
  14.     printf("The new array after right shift is:-\n");
  15.     for(i=0; i<n;i++)
  16.         printf("%d",a[i]);
  17.     return 0;
  18. }
  19. //Output
  20. //Enter the array's limit: 5
  21. //Now enter 5 elements to fill the array.
  22. //1
  23. //2
  24. //3
  25. //4
  26. //5
  27. //The new array after right shift is:-
  28. //51234
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement