#include <iostream> using namespace std; int fib(int number) { int value = 0; if(number < 1) return 0; if(number == 1) return 1; return fib(number-1) + fib(number - 2); } int main() { int row = 15; int column = 15; int arr[row][column]; int arrQuantity[15]; for (int i = 0; i < column; i++) { for (int j = 0; j < row; j++){ arr[i][j] = rand()%100-50; cout << arr[i][j] << "\t"; } cout << endl; } for (int i = 0; i < row; i++){ arrQuantity[i] = 0; for (int k = 0; k < column; k++){ for(int j = 0; j < 13; j++){ if(arr[i][k] == fib(j)) arrQuantity[i] +=1; } } } cout << "Кількість чисел Фібоначчі: " ; for(int i = 0; i < column; i++) cout << arrQuantity[i]; for(int i = 0; i < column; i++){ if(arrQuantity[i] > arrQuantity[i + 1]){ for(int j = 0; j < row; j++){ swap(arr[i][j], arr[i + 1][j]); } } } cout << "\n\n\n"; for (int i = 0; i < column; i++){ for (int j = 0; j < row; j++) cout << arr[i][j] << "\t"; cout << endl; } return 0; } 

Need to improve the program. The meaning of the program is to sort the array columns by the number in the columns of Fibonacci numbers. You need to sort by ascending, that is, from left to right.

  • In what sense to improve? If the program works, what's not good enough? - VladD
  • @VladD, probably because there is no sorting in it ... - avp
  • one
    @avp: Then this is some new, unknown to me meaning of the word “improve”. - VladD
  • @VladD, it seems, by its modesty, the TS forgot to add dramatically - avp

1 answer 1

 #include <iostream> using namespace std; int fib(int number) { int value = 0; if(number < 1) return 0; if(number == 1) return 1; return fib(number-1) + fib(number - 2); } int main() { int row = 10; int column = 10; int arr[row][column]; int arrQuantity[10]; for (int i = 0; i < column; i++) { for (int j = 0; j < row; j++){ arr[i][j] = rand()%100-50; } } for(int i = 0; i < column;i++){ for(int j = 0; j < row;j++){ cout << arr[j][i] << "\t"; } cout << endl; } for (int i = 0; i < row; i++) { arrQuantity[i] = 0; for (int k = 0; k < column; k++) { for(int j = 0; j < 13; j++){ if(arr[i][k] == fib(j)) arrQuantity[i] +=1; } } } cout << "Кількість чисел Фібоначчі: " ; for(int i = 0; i < column; i++) cout << arrQuantity[i]; check: for(int i = 0; i < column; i++){ if(arrQuantity[i] < arrQuantity[i + 1]){ for(int j = 0; j < row; j++){ swap(arr[i][j], arr[i + 1][j]); } swap(arrQuantity[i], arrQuantity[i+1]); goto check; } } cout << "\n\n\n"; for (int i = 0; i < column; i++) { for (int j = 0; j < row; j++) cout << arr[j][i] << "\t"; cout << endl; } return 0; }