fork download
  1. #include <stdio.h>
  2.  
  3.  
  4. int main() // use properly
  5. {
  6. int n,i;
  7.  
  8. //array size input
  9. scanf("%d",&n);
  10. int a[100]; //edit
  11.  
  12. //array elements input
  13. for(i=0;i<n;i++)
  14. {
  15. scanf("%d",&a[i]);
  16. }
  17.  
  18. // shift amount input
  19. int s,temp,j;
  20. scanf("%d",&s);
  21.  
  22.  
  23. for(i=0;i<s;i++)
  24. {
  25. temp=a[n-1];
  26.  
  27. for(j=n-1;j>0;j--) // use different variable here
  28. a[j]=a[j-1];
  29.  
  30. a[0]=temp;
  31. }
  32.  
  33. //Output of shifted array
  34. for(i=0;i<n;i++)
  35. {
  36. printf("%d\n",a[i]);
  37. }
  38.  
  39. return 0; // exit success
  40. }
Success #stdin #stdout 0s 2172KB
stdin
5
1 2 3 4 5
3
stdout
3
4
5
1
2