Breaking News

C Program to reverse an array

Source Code-
#include
int main()
{

    int n, i, j, a[100], b[100];

    printf("Enter the number of elements in array\n");
    scanf("%d", &n);

    printf("Enter the array elements\n");

    for (i = 0; i < n ; i++)
     scanf("%d", &a[i]);

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

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



    printf("The Reversed array is\n");

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

    return 0;
}
output-

No comments

shankhajana. Powered by Blogger.