output array c++ code example
Example 1: print array c++
void printArray(int a[],int n){
for(int i=0;i<n;i++)
cout<<a[i]<<" ";
cout<<endl;
}
Example 2: print an array c++
#include <iostream>
using namespace std;
int main() {
int numbers[5] = {7, 5, 6, 12, 35};
cout << "The numbers are: ";
for (const int &n : numbers) {
cout << n << " ";
}
cout << "\nThe numbers are: ";
for (int i = 0; i < 5; ++i) {
cout << numbers[i] << " ";
}
return 0;
}
Example 3: prints out the elements in the array c++
for (auto i : a){
cout << i<< " ";
}