array reversing

#include <stdio.h>
void arr_rev(int arr[])//reversing array user built function
{
    for(int i=0;i<5/2;i++)
    {
        //swaping method
        int temp;
        temp=arr[i];
        arr[i]=arr[4-i];
        arr[4-i]=temp;
    }
}

int main()
{
    int arr[]={1,2,3,4,5};
    for(int j=0;j<5;j++)
    {
        printf("element of %d is %d\n",j,arr[j]);
    }
    printf("reversed array\n");
    arr_rev(arr);
    for(int j=0;j<5;j++)
    {
        printf("element of %d is %d\n",j,arr[j]);
    }
    return 0;
}

Comments

Popular posts from this blog

Steps taken by a compiler to execute a C program

Tokens in C

Variables and Data Types in C