65.9k views
2 votes
write a function void print( ) which initializes a single dimensional array of ar [ ] of 15 integers and print the sum of all integers which are present at odd indexes

1 Answer

6 votes

Final answer:

The student's question is about creating a function that initializes a one-dimensional array of 15 integers and calculates the sum of elements at odd indices, then prints this sum. An example in C++ programming language is provided to demonstrate this functionality.

Step-by-step explanation:

The student is asking for a function in programming that initializes a one-dimensional array with 15 integer elements and prints the sum of the integers which are located at odd indices. Below is the example implementation in C++:

void print() {
int ar[15] = {0}; // or initialize with some values
int sum = 0;

// Calculate the sum of integers at odd indexes
for (int i = 1; i < 15; i += 2) {
sum += ar[i];
}

// Print the sum
std::cout << "The sum of integers at odd indexes is: " << sum << std::endl;
}

Here, the array ar[] is initialized with default or specific integers, and a loop is used to add the elements at odd indexes. After the loop completes, it prints out the sum of these elements.

User Singulus
by
7.6k points