Hi, guys in this post we will see about
Reverse of an array using c and c++
*c++ code
#include <iostream>
using namespace std;
//Compiler version g++ 6.3.0
int main()
{
int a[5]={1,2,3,4,5};
int temp ;
int i=4;
int j=0;
for(i=4;i>5/2;i--)
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
j++;
}
for(int k=0;k<5;k++){
cout<<a[k];
}
}
C code
#include<stdio.h>
//Compiler version g++ 6.3.0
int main()
{
int a[5]={1,2,3,4,5};
int temp ;
int i=4;
int j=0;
for(i=4;i>5/2;i--)
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
j++;
}
for(int k=0;k<5;k++){
Printf("%d",a[k]);
}
}
Comments
Post a Comment