write a program to print the sum of even and product of odd from 1 to 100
Answers
Answer:
if you are pleased with answer in turn
please subscribe my youtube chanel(Ramakrishna Nallangari youtube channel) for my effort
search for
Ramakrishna Nallangari in search box
of youtube
Explanation:
python:
# Python program to find out
# Sum of elements at even and
# odd index positions separately
# Function to calculate Sum
def EvenOddSum(a, n):
even = 0
odd = 0
for i in range(n):
# Loop to find evem, odd Sum
if i % 2 == 0:
even += a[i]
else:
odd += a[i]
print "Even index positions sum ", even
print "nOdd index positions sum ", odd
# Driver Function
arr = [1, 2, 3, 4, 5, 6]
n = len(arr)
EvenOddSum(arr, n)
# This code is contributed by Sachin Bisht
Output:
Even index positions sum 9
Odd index positions sum 12
c/c++:
// 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;
}
Output:
Even index positions sum 9
Odd index positions sum 12
if you are pleased with answer in turn
please subscribe my youtube chanel(Ramakrishna Nallangari youtube channel) for my effort
search for
Ramakrishna Nallangari in search box
of youtube