Nov 22, 2020 at 12:04pm UTC
Hi guys, how can i get the 3/4 of
one-dimensional array(vector) in a program?
Nov 22, 2020 at 12:14pm UTC
corepower wrote:Hi guys, how can i get the 3/4 of
one-dimensional array(vector) in a program?
Do you mean you want a sub-vector three-quarters of the size ...
or the 75th percentile ...
or something else?
Last edited on Nov 22, 2020 at 12:23pm UTC
Nov 22, 2020 at 12:15pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#include <iostream>
using namespace std;
int main()
{
int vec[99], i, n;
cout << "\nNr. elementelor = " ;
cin >> n;
for (i = 0; i < n; i++) {
cout << "\nElement = " ;
cin >> vec[i];
}
}
I mean in a program of this type. The 3/4 or 0,75.
Last edited on Nov 22, 2020 at 12:16pm UTC
Nov 22, 2020 at 12:17pm UTC
Actually i want to find the arithmetic mean of the odd numbers from the first 3/4 of the vector
Nov 22, 2020 at 12:18pm UTC
corepower wrote:Actually i want to find the arithmetic mean of the odd numbers from the first 3/4 of the vector
Make your mind up!
Last edited on Nov 22, 2020 at 12:24pm UTC
Nov 22, 2020 at 12:19pm UTC
That's the full condition
Nov 22, 2020 at 12:19pm UTC
I just need to know how to get the first 3/4 of the vector
Nov 22, 2020 at 12:19pm UTC
If the (array) has 99 elements, how many elements would you like the "0.75" of it to have?
Nov 22, 2020 at 12:20pm UTC
how many i introduce from the cin>>n
Nov 22, 2020 at 12:21pm UTC
corepower wrote:how many i introduce from the cin>>n
Let me ask you again ... if the (array) has 99 elements, how many elements would you like the "0.75" of it to have?
Maybe you would like to state the original question, NOT your interpretation of it.
Last edited on Nov 22, 2020 at 12:24pm UTC
Nov 22, 2020 at 12:35pm UTC
the array doesnt have 99 elements, it have as much as i want to introduce from the keyboard, as you see in the program of above.
Nov 22, 2020 at 12:36pm UTC
It's given a one-dimensional array (vector), find the arithmetic mean of the odd numbers from the first 3/4 of the vector.
This is the original condition
Nov 22, 2020 at 12:38pm UTC
how many i introduce from the cin>>n
If you use
n
first elements from array that has 99 elements, then you use "
n/99 of the array".
The n/99 is equal with 3/4,
if and only if the user gives correct value for n.
If you want 3/4, then you calculate and use the correct
n and do not ask it from the user.
[EDIT]
Ok. You have array with
n
elements. Surely you can calculate
int k
, where k/n is about 3/4?
Last edited on Nov 22, 2020 at 12:41pm UTC
Nov 22, 2020 at 12:43pm UTC
nope, i want to do it with a loop and just with iostream
Nov 22, 2020 at 12:47pm UTC
Corepower, if your array has 5 elements (i.e. you input 5 from the keyboard), what is three-quarters of that?
Note that 0.75 *5 is 3.75, nearest to 4 as a whole number,
whereas 5 * 3 /4 (with integer division) is 3
So, clarify your problem.
Nov 22, 2020 at 1:13pm UTC
I think @corepower is trying to say that it's not that array(vector) but the other one.
Nov 22, 2020 at 1:20pm UTC
omg guys why its so hard to understand
1.i introduce the number of elemets from the keyboard
2. i introduce the elements
3. the program returns me the arithmetic mean of the odd numbers from the first 3/4 of the numbers i introduced
Nov 22, 2020 at 1:23pm UTC
Well, as long as n is divisible by 4 then either of seeplus's codes solves your problem.
Why is it so hard to understand ... well look back at your first post!