Computer Science, asked by justheretocopy, 9 months ago

[Computer- Array]
Write a java program to accept 10 numbers into an int array and calculate and display the sum of numbers present in the odd and even positions respectively.

Answers

Answered by Anonymous
3

Answer:

// CPP program to find out

// Sum of elements at even and

// odd index positions separately

#include <iostream>

using namespace std;

// Function to calculate sum

void EvenOddSum(int arr[], int n)

{

int even = 0;

int odd = 0;

for (int i = 0; i < n; i++) {

// Loop to find even, odd sum

if (i % 2 == 0)

even += arr[i];

else

odd += arr[i];

}

cout << "Even index positions sum " << even;

cout << "\nOdd index positions sum " << odd;

}

// Driver function

int main()

{

int arr[] = { 1, 2, 3, 4, 5, 6 };

int n = sizeof(arr) / sizeof(arr[0]);

EvenOddSum(arr, n);

return 0;

Answered by rahul1644
7

the complete program is in the photo sent

Attachments:
Similar questions