Discharge the main function



  • int cod17(int A[]) {    //Входные параметры: массив
        int j, a, n, s, k;  //Локальные переменные
        for (j = 0, a = 10; a < 30000; a++) {   //Цикл: диапазон от 0 до 30000
            for (n = a, s = 0; n != 0; n = n / 10)  //Цикл с перебором цифр числа а
            {
                k = n % 10; //отделяем поочередно последнюю цифру числа
                s = s + k; //находим сумму цифр
            }
            if (a == s * s * s) A[j++] = a; //условие проверки: если куб суммы цифр равен числу, то добавляем число в массив
        }
    }
    


  • The code is semantic and logically written very badly, nothing personal, it's more like a comment that it's hard to figure out. I agree with Dafter that you're sending an index to the mass, that is, changing its elements directly alters the elements in your main body (more information: https://metanit.com/cpp/c/5.1.php#:%7E:text=%D0%A3%D0%BA%D0%B0%D0%B7%D0%B0%D1%82%D0%B5%D0%BB%D0%B8%20%D0%BF%D1%80%D0%B5%D0%B4%D1%81%D1%82%D0%B0%D0%B2%D0%BB%D1%8F%D1%8E%D1%82%20%D1%81%D0%BE%D0%B1%D0%BE%D0%B9%20%D0%BE%D0%B1%D1%8A%D0%B5%D0%BA%D1%82%D1%8B%2C%20%D0%B7%D0%BD%D0%B0%D1%87%D0%B5%D0%BD%D0%B8%D0%B5%D0%BC,%D1%83%D0%BA%D0%B0%D0%B7%D0%B0%D1%82%D0%B5%D0%BB%D1%8C%2C%20%D0%B8%20%D1%81%D0%B8%D0%BC%D0%B2%D0%BE%D0%BB%20%D0%B7%D0%B2%D0%B5%D0%B7%D0%B4%D0%BE%D1%87%D0%BA%D0%B8%20*. ) But what I'm going to say is that it's a danger that lies in the transfer of such masses. You or tolerate this kind of mass as either "special" meaning (which also depends on the logic of use that can be obtained in the case of a mass of ints) or give the same size.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2