Computer Science, asked by romybholath61, 8 months ago

Write a program to create a list of 6 numbers and find the sum of evenind
odd numbers in the list. e.gif list is[2,4,5,7,1,9). Output should be
Sum of Even number = 6
Sum of Odd numbers 22​

Answers

Answered by 03ns19
0

Answer:

in python

def EvenOddSum(a, n):

even = 0

odd = 0

for i in range(n):

if i % 2 == 0:

even += a[i]

else:

odd += a[i]

print "Even index positions sum ", even

print "nOdd index positions sum ", odd

arr = [1, 2, 3, 4, 5, 6]

n = len(arr)

EvenOddSum(arr, n)

in c/c++

#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 coolaayesha
0

Are you talking about computer program that will give the output as you have shown, If yes then you should use any spreadsheet software like Microsoft Excel.

Similar questions