New course! Every coder should learn Generative AI!
Try a free lesson+ 3
C++
We have an n-element integer array. Find the arithmetic mean of the even-indexed elements
8 Answers
+ 2
For searching of even elemets you could take ie. modulo method:
if(x%2 == 0)
{your code}
+ 2
Balaxanim
your code have a lot of errors.
syntax: int, for, s, return are supposed to be lowercase.
your array a[n] is never initialized.
your for loop is doing nothing to the sum or the array.
you are not displaying your s, which remains 0 throughout.
do you really need to define n?
why not just use a[10]?
+ 1
What is your question?
First of all, do you know the artmetic definition of that what you ask?
Can you tell this definition and data input output with a small arrays?
+ 1
Thank you 🩵
0
#include <iostream>
#define n 10
Using namespace std;
Int main () {
Int a[n], s=0;
For (int i=0;i<n; i+=2)
S+= a[i];
Return 0;
}
This is Odd index element but I need an even index element but it doesn't work, what did I do wrong, what should I fix?
0
I know syntaxs supposed to be lowercase. I have an exam tomorrow I need to raise I didn't fully understand the question, so I wrote it here.
0
Hi
0
To reduce the time complexity to check if the number is even or not....u can use & operator....if (n& (n-1))==0)
Then n is even number