Jump to content
H3xoR

[Easy]C++ Challenge

Recommended Posts

Un mic challenge, utilizand o metoda recursiva. Inversati elementele egal departate de extremitatiile unui vector.

Raspunsuri prin PM.

Solvers: skull, totti93, cmiN, Sega.

Challenge terminat!!!

O metoda scrisa de mine( cea mai usoara din toate cele vazute ):

#include <iostream>
using namespace std;
void Reverse( int a[], int n )
{
if( n / 2 )
{
int aux = *a;
*a = a[n-1];
a[n-1] = aux;
Reverse( a + 1, n - 2 );
}
}
int main( void )
{
int a[20], n;
cout << "n = ", cin >> n;
for( int i = 0; i < n; i++ )
cout << "a[" << i << "] = ", cin >> a[i];
Reverse( a, n );
for( int i = 0; i < n; i++ )
cout << a[i] << ' ';
return 0;
}

Edited by H3xoR
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...