Answers for "Array Reverse In Groups of M"

C
0

Array Reverse In Groups of M

#include<stdio.h>
int* reverse(int* arr, int length, int M){
    int left=0,right=M-1;
    while(right<length){
        int i=left,j=right;
        while(i<j){
            int t=arr[i];
            arr[i]=arr[j];
            arr[j]=t;
            i++;j--;
        }
        left+=M;
        right+=M;
    }
    return arr;
}
int main()
{
    int N,M;
    scanf("%d",&N);
    int arr[N];
    int index;
    for(index=0; index < N; index++)
    {
        scanf("%d",&arr[index]);
    }
    scanf("%d",&M);
    reverse(arr,N,M);
    for(index=0; index < N; index++)
    {
        printf("%d ",arr[index]);
    }
    return 0;
}
Posted by: Guest on August-21-2021

Code answers related to "Array Reverse In Groups of M"

Code answers related to "C"

Browse Popular Code Answers by Language