C C++ program to reverse elements of array

C C++ program to reverse elements of array

C Language में Array और इसके विभिन्न प्रकारो के बारे में और अधिक जानने के लिए देखें— Arrays in C

Pointer और इसके कार्य करने के तरीके को आधिक जानने के लिए देखें यह पोस्ट—Pointers in C

C Language में Structure क्या होता है और इसका प्रयोग क्यो किया जाता है जानने के लिए देखें—Structures in C

C program to reverse elements of array

#include<stdio.h>
int main()
{
    int arr[5],rev[5],i,j=4;
    printf("Enter elements of array: \n");
    for(i=0;i<5;i++)
    {
        scanf("%d",&arr[i]);
    }
    for(i=0;i<5;i++)
    {
        rev[i]=arr[i];
    }
    for(i=0;i<5;i++)
    {
         arr[i]=rev[j];
         j--;
    }
    printf("Reverse order of array: \n");
    for(i=0;i<5;i++)
    {
        printf("%d ",arr[i]);
    }
    return 0;
 }

C++ program to reverse elements of array

#include<iostream>
using namespace std;
int main()
{
    int arr[5],rev[5],i,j=4;
    cout<<"Enter elements of array: \n";
    for(i=0;i<5;i++)
    {
        cin>>arr[i];
    }
    for(i=0;i<5;i++)
    {
        rev[i]=arr[i];
    }
    for(i=0;i<5;i++)
    {
         arr[i]=rev[j];
         j--;
    }
    cout<<"Reverse order of array: \n";
    for(i=0;i<5;i++)
    {
        cout<<arr[i]<<" ";
    }
    return 0;
 }

Output of C C++ program to reverse elements of array

C CPP program to reverse elements of array

Helpful example program of array in C C++

  1. Declaration and initialization of array
  2. Input-output in array
  3. Sum and average of array elements
  4. Largest Element in Array
  5. Smallest element in Array
  6. Merging two arrays
  7. Searching in array (Linear search)
  8. Sorting in array (Selection sort)
  9. Pointer to array
Share it to:

Published by

admin

I am a computer teacher, programmer and web developer