Friday, October 28, 2022

Change by pairs

 #include <iostream>
#include <math.h>
using namespace std;
#define N 9
int main()
{   int a[N],b;
    for (int i = 0; i < N; i++) a[i] = rand() % 10;
    for (int i=0; i < N; i++) cout << a[i]<<" ";
    cout << "\n";
    //
    // Input here your code 
    //  
    // Inputted code:
    for (int i = 0; i < N-1; i = i + 2) 
    {
        b = a[i]; 
        a[i] = a[i + 1]; 
        a[i + 1] = b;
    }
    
    //
    for (int i=0; i < N; i++) cout << a[i] << " ";
    cout << "\n";
 }

No comments:

Post a Comment

N-point Star in Microsoft Visual Studio Console App

#include <windows.h> #include <cmath> #include <iostream> LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,...