Задан двумерный массив в из 6-и строк и 3-х столбцов. составить программу, которая организует одномерный массив с, элементы которого равны количеству положительных элементов в строке исходного массива в. программа с++, найти ошибку в коде #include #include #include #include using namespace std; int main() { setlocale(lc_all, "russian"); system ("cls"); cout< < "\t \t лабораторная работа № 5. двумерный массив"< int b[6][3]; int cnt_positive[6]; int i; int j; int ki=6; //кол. строк int kj=3; //кол. столбцов for (i=0; i { for (j=0; j { cout < < "введи элемент массива b["< < i < < ","< < j < < "] = "; cin> > b[i][j]; } } cout< < "массив b" < for (i=0; i { for (j=0; j {cout< } cout< } // for (i=0; i { cnt_positive[i]=0; for (j=0; j {if(b[i][j] > 0) cnt_positive[i]++; } } cout< < "линейный массив cnt_positive[6] из матрицы b[6][3]: "< < endl; for (i=0; i< 6; i++) {cout< < cnt_positive[i] < < "\t"; } cout< < endl; system("pause"); return 0; }
#include <cmath>
using namespace std;
bool prost(int m){
int k = 0;
for (int i=2; i<=sqrt(m); i++)
if (m % i == 0) k++;
return k==0;
}
int main(){
int n, r;
int i = 1;
cout << "n = ", cin >> n, cout << "\n";
if (prost(n)) {
cout << "1 * " << n << " = " << n << "\n";}
else {
r = n;
while (r != 1){
i++;
if (prost(i)){
while (r % i == 0){
r = r / i;
cout << i;
if (r != 1) cout << "*";
}
}
}
cout << "=" << n << "\n";
}
return 0;
}
Пример:
n = 2720
2*2*2*2*2*5*17=2720