Gave the task:

Enter a one-dimensional array, display it. Find the product of its elements belonging to the interval [min / 2, max / 2]. The value of this product to replace the first and penultimate elements of the array.

Written array input and output. I do not understand how "to find the product of its elements belonging to the interval [min / 2, max / 2]"

#include <stdio.h> using namespace std; int main() { int mass [N]; for(int i = 0 ; i<N ; i++) scanf (&mass[i]); for(int i = 0 ; i<N ; i++) printf ("%d", mass[i]); return 0; } 

Closed due to the fact that off-topic participants Denis , Vladimir Martyanov , dirkgntly , free_ze , Harry 18 Aug '16 at 13:27 .

  • Most likely, this question does not correspond to the subject of Stack Overflow in Russian, according to the rules described in the certificate .
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • five
    I vote for the closure of this issue as not relevant topic, because there does not solve the training tasks for others. - Denis
  • And what particular difficulties do you have? Show your achievements. - s8am
  • I do not need a solution entirely, I want to understand how "to find the product of its elements belonging to the interval [min / 2, max / 2]" - Stepan Kotov
  • #include <stdio.h> using namespace std; int main () {int mass [N]; for (int i = 0; i <N; i ++) scanf (& mass [i]); for (int i = 0; i <N; i ++) printf ("% d", mass [i]); return 0; } - Stepan Kotov
  • one
    @ Stepan Kotov Teacher ask? ... - free_ze

1 answer 1

Eh, I didn’t write from 1 course on C. The author made small attempts to create a program, it is simple, I suggest to help.

I tried to correct the question in order to have at least some benefit. If you think that this is still a decision for the author and the question is useless in the future, then I will delete the answer.

ideone

 #include <stdio.h> int main(void) { int mass[] = {2, 2, -3, 1, 5}; // сразу Π·Π°ΠΏΠΎΠ»Π½ΠΈΠΌ массив int N = sizeof (mass) / sizeof (int); // ΡƒΠ·Π½Π°Π΅ΠΌ Π΅Π³ΠΎ Π΄Π»ΠΈΠ½Ρƒ double min = mass[0], max = mass[0], pr = 1; //for(int i = 0 ; i<N ; i++) // scanf (&mass[i]); for(int i = 0 ; i<N ; i++) { printf ("%d, ", mass[i]); if (min > mass[i]) // ΠΈΡ‰Π΅ΠΌ ΠΌΠΈΠ½ΠΈΠΌΠ°Π»ΡŒΠ½Ρ‹ΠΉ элСмСнт min = mass[i]; if (max < mass[i]) // ΠΈΡ‰Π΅ΠΌ ΠΌΠ°ΠΊΡΠΈΠΌΠ°Π»ΡŒΠ½Ρ‹ΠΉ элСмСнт max = mass[i]; } printf ("\n"); min = min / 2; // Π΄Π΅Π»Π°Π΅ΠΌ эти Π³Ρ€Π°Π½ΠΈΡ†Ρ‹ min/2 ΠΈ max/2 max = max / 2; for (int i = 0; i < N; i++) { if (mass[i] >= min && mass[i] <= max) { pr = pr * mass[i]; // Π½Π°Ρ…ΠΎΠ΄ΠΈΠΌ ΠΏΡ€ΠΎΠΈΠ·Π²Π΅Π΄Π΅Π½ΠΈΠ΅ Ρ‚Π΅Ρ… элСмСнтов, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ Π² Π΄Π°Π½Π½ΠΎΠΌ ΠΎΡ‚Ρ€Π΅Π·ΠΊΠ΅ } } mass[0] = pr; // замСняСм mass[N-2] = pr; for(int i = 0 ; i<N ; i++) { printf ("%d, ", mass[i]); // profit } return 0; } 
  • what does sizeof (int) mean? - Stepan Kotov
  • sizeof(int) - returns the size of type int in bytes in my opinion. sizeof (mass) returns the size of the array in bytes. Therefore, to find out how many elements, we divide one by the other. - Denis
  • one
    To get N, it is better to write sizeof(mass) / sizeof(mass[0]) right away, if (of course, not in this program) the type changes when processing the program, then you will not have to change the code that calculates the size of the array. And yet, when searching for min and max you can safely write an else between these if -s - avp