Answers for "how to print an array in cpp in single line"

C++
0

how to print an array in cpp in single line

int Grades[5] = { 3, 2, 5, 2 };

cout << "Grades: ";
for (int i = 0; i < sizeof(Grades)/sizeof(int); i++) {
    cout << Grades[i] << ", "; //minus the commas, remove (<< ", ") or to space out the grades, just remove the comma
}
Posted by: Guest on October-29-2020

Code answers related to "how to print an array in cpp in single line"

Browse Popular Code Answers by Language