Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In Visual Logic. You will create a program with two methods, the main() method o

ID: 3591433 • Letter: I

Question

In Visual Logic. You will create a program with two methods, the main() method of course and another method called printArray(). The main method will define an array of 5 elements. A loop will be used to prompt the user to enter 5 numeric values which will go into the 5 array elements. The main() method will then call the printArray() method passing the array by reference, and the array length by value. The printArray() method will then print the contents of the array, 0th element first and return.

Explanation / Answer

Solution:

#include <iostream>
using namespace std;
void printArray(int a[], int size) {
cout<<"Array elements are: "<<endl;
for(int i=0;i<size;i++) {
cout<<a[i]<<" ";
}
cout<<endl;
}
int main()
{
int a[5];
for(int i=0;i<5;i++) {
cout<<"Enter the number "<<(i+1)<<": "<<endl;
cin >> a[i];
}
printArray(a, 5);
return 0;
}

Output:

Please, please upvote and ask your doubts in the comments.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote