
LANGUAGE: C++
CHALLENGE:
Write the definition of a function printArray, which has two parameters. The first parameter is an array of int s and the second is an int, the number of elements in the array. The function does not return a value. The function prints out each element of the array, on a line by itself, in the order the elements appear in the array, and does not print anything else.
SOLUTION:
void printArray (int s[],int n){ for (int k=0; k<n; k++){ cout << s[k] << endl } }
void printArray (int s[],int n){
for (int k=0; k<n; k++)
cout << s[k] << endl;
}
Missing a semicolin
void printArray (int s[],int n)
{
for (int k=0; k<n; k++)
{cout << s[k] << endl;}
}
Here is the code in C:
void printArray (int s[],int n){
int k;
for (k=0; k<n; k++){
printf("%d\n", s[k]);
}
}