A
A
ashot_powershot2021-11-15 13:40:39
C++ / C#
ashot_powershot, 2021-11-15 13:40:39

Why is it unclear to me and how to fix it?

The replacement is correct (I checked it step by step), but the conclusion is not the same

#include<iostream>
#include <cstring>
#include<cmath>
#include<cstdlib>
#include<conio.h>


using namespace std;
int main()
{
  setlocale(LC_ALL, "RUS");

  const int n = 5;
  double b[5], c[5];
  int i, a=0,g=0;
  cout << "Массив b = " << endl;
  for (i = 0; i < n; i++)
  {
    cin >> b[i];
    if (b[i] > 0)
    {
      for (a; a <= i; a++)
      {
        c[a] = b[i];
        g++;
      }
      a = g;
    }
  }
  cout << "Сжатие массива = " << c[a] << endl;
  system("PAUSE");

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2021-11-15
@wataru

Exactly what you asked to be displayed is displayed - an uninitialized element of the array c.
Think about what is equal aat the end of the program?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question