hasan-mahmudz

Array Item Reverse

Jan 28th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.66 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main()
  5. {
  6.     int n;
  7.     scanf("%d", &n, printf("Enter the Array size: "));
  8.  
  9.     int a[n];
  10.     int splitSize;
  11.     scanf("%d", &splitSize, printf("How many items in each section: "));
  12.  
  13.     int i, j, k;
  14.  
  15.     for(i = 0; i < n; i++){
  16.         scanf("%d", &a[i], printf("A[%d] : ", i));
  17.     }
  18.  
  19.     i = 0;
  20.     while(i <= n){
  21.         if(i + splitSize >= n){
  22.             j = i + (n - i) - 1;
  23.         }else{
  24.             j = i + (splitSize - 1);
  25.         }
  26.        
  27.         for(k = j; k >= i; k--){
  28.             printf("%d ", a[k]);
  29.         }
  30.  
  31.         printf(" ");
  32.         i += splitSize;
  33.     }
  34.  
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment