Menu
Coddy logo textTech

Recap - Pretty Print Array

Part of the Fundamentals section of Coddy's C++ journey — lesson 61 of 74.

challenge icon

Challenge

Easy

Create a program that:

  1. Receives n: the number of elements in the array
  2. Then receives n strings to populate the array

Print the array beautifully in the following format:

[elem1, elem2, elem3, ...]

Try it yourself

#include <iostream>

int main() {
    int n;

    std::cin >> n;
    std::cin.ignore();
    std::string arr[n];
    
    for (int i = 0; i < n; i++) {
        std::string val;
        std::cin >> val;
        arr[i] = val;
    }
    
    // Print the array beautifully
    
    return 0;
}

All lessons in Fundamentals