fork download
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <stdlib.h>
  4. int main(void) {
  5. int osn,i,n,bot,top,top1,*a,*b;
  6. scanf("%d",&n);
  7. a=(int*)malloc(n*sizeof(int));
  8. b=(int*)malloc(n*sizeof(int));
  9. //srand(time(NULL));
  10. top=-1;
  11. while (top<n-1)
  12. {
  13. top++;
  14. a[top]=1+rand()%50;
  15. printf("%d %d\n",top,a[top]);
  16. }
  17. osn=a[top--];
  18. top1=-1;
  19. while (top>=0)
  20. {top1++;
  21. b[top1]=a[top];
  22. top--;
  23. }
  24. b[++top1]=osn;
  25. while(top1>=0)
  26. {top++;
  27. a[top]=b[top1];
  28. top1--;
  29. }
  30. bot=0;
  31. while (top>=bot)
  32. {
  33. printf("╚═%d═╝\n",b[bot++]);}
  34. printf("osn=%d\n",osn);
  35. return 0;
  36. }
Success #stdin #stdout 0s 4504KB
stdin
5
stdout
0 34
1 37
2 28
3 16
4 44
╚═16═╝
╚═28═╝
╚═37═╝
╚═34═╝
╚═44═╝
osn=44