Even Odd - C++
Wed Feb 19 2025 02:15:53 GMT+0000 (Coordinated Universal Time)
Saved by
@Rohan@99
#include <iostream>
using namespace std;
void PrintArray(int a[], int n)
{
for(int i = 0; i < n; ++i)
cout << a[i] << " ";
}
int main()
{
int n, p1 = 0, p2 = 0;
cin >> n;
int a[n];
for(int i = 0; i < n; ++i)
cin >> a[i];
while(p2 < n)
{
if(a[p2] % 2 == 0)
{
swap(a[p1], a[p2]);
++p1;
}
++p2;
}
PrintArray(a, n);
return 0;
}
content_copyCOPY
Comments