The program was written to sort the numbers (in descending order) code in visual studio

#include "stdafx.h" #include <iostream> #include <math.h> using namespace std; int main() { setlocale(LC_CTYPE, "rus"); const int n = 10000; int mass[n]; int len,temp; cout << "Размер="; cin >> len; for (int i = 0; i < len; i++) { cout << "["<<i<<"]="; cin >> mass[i]; } for (int i = 0; i < len; i++) { for (int j = i+1; i < len; j++) { if (mass[i] < mass[j]) {//ошибка здесь temp = mass[i]; mass[i] = mass[j]; mass[j] = temp; } } } for (int i = 0; i < len; i++) { cout << "[" << i << "]=" << mass[i] << endl; } cout << "\n"; system("pause"); } 

Closed due to the fact that off-topic participants VTT , 0xdb , AnT , freim , aleksandr barakin February 17 at 15:46 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reasons:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - VTT, AnT, aleksandr barakin
  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - 0xdb, freim
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Vangui out of the array. - ArchDemon
  • in for (int j = i+1; i < len; j++) typo, must be for (int j = i+1; j < len; j++) - VTT

1 answer 1

for (int j = i+1; i < len; j++) - going beyond the array. j -> to infinity.

  • blenb, banal not attentive, forgot to change i to j (need to use ctr + v less), thanks - Tomato Tomatoes