Program to reverse the array solution using c language--programming_info problem 10

Program to reverse the array.

This above example is just a reference picture. don't
think it as an input of an array.
you can give your own input.

#include<stdio.h>
#include<conio.h>

void main()
{
    int size, i, j, a[100], b[100];
    clrscr();

    printf("Enter the size of array : ");
    scanf("%d", &size);

    for (i = 0; i < size; i++)
    {
        printf("Enter element %d :", i);
        scanf("%d", &a[i]);
    }

    /*
     * Copying elements into array b starting from end of array a
     */

    for (i = size - 1, j = 0; i >= 0; i--, j++)
        b[j] = a[i];

    /*
     * Copying reversed array into original.
     * Here we are modifying original array, this is optional.
     */

    for (i = 0; i < size; i++)
        a[i] = b[i];

    printf("Reverse array is :\n");

    for (i = 0; i < size; i++)
        printf("%d\n", a[i]);

    getch();
}
Share:

No comments:

Post a Comment

Translate

Recommended platforms

  1. codechef
  2. hackerrank
  3. codeforces
  4. leetcode
  5. hackerearth

Popular Posts

programming_info. Powered by Blogger.

Blog Archive

Recent Posts

other platforms

  • geeks for geeks
  • w3schools
  • codepen
  • skillshare
  • udemy

Pages

reader support Support