Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstdlib>
- #include <iostream>
- #include <cmath>
- #include <ctime>
- using namespace std;
- int main(){
- srand(time(0));
- setlocale(0,"");
- int n;
- int m;
- int a;
- int b;
- cout<<"Введите количество строк"<<endl;
- cin>>n;
- cout<<endl<<"Введите количество столбцов"<<endl;
- cin>>m;
- const int str=n;
- const int stl=m;
- int ar[str][stl];
- cout<<endl<<"Массив будет заполнен случайными числами от..."<<endl;
- cin>>a;
- cout<<endl<<"До..."<<endl;
- cin>>b;
- b+=abs(a)+1;
- if (a<0) a*=-1;
- for (int i=0;i<str;i++){
- for (int j=0;j<stl;j++){
- ar[i][j]=rand()%b-a;
- }
- }
- cout<<endl;
- cout<<"Исходный массив"<<endl;
- for (int i=0;i<str;i++){
- for (int j=0;j<stl;j++){
- cout<<ar[i][j]<<" ";
- }
- cout<<endl;
- }
- for (int i=0;i<str;i++){
- for (int j=0;j<stl;j++){
- if (ar[i][j]%2==0) ar[i][j]/=2;
- else ar[i][j]=pow(ar[i][j],2);
- }
- }
- cout<<endl;
- cout<<"Новый массив"<<endl;
- for (int i=0;i<str;i++){
- for (int j=0;j<stl;j++){
- cout<<ar[i][j]<<" ";
- }
- cout<<endl;
- }
- }
- ------------------------------
- #include <cstdio>
- #include <cstdlib>
- #include <iostream>
- #include <ctime>
- using namespace std;
- int main(){
- srand(time(0));
- setlocale(0,"");
- double n;
- int m;
- int a;
- int b;
- cout<<"Введите количество строк"<<endl;
- cin>>n;
- cout<<endl<<"Введите количество столбцов"<<endl;
- cin>>m;
- const int str=n;
- const int stl=m;
- int ar[str][stl];
- cout<<endl<<"Массив будет заполнен случайными числами от..."<<endl;
- cin>>a;
- cout<<endl<<"До..."<<endl;
- cin>>b;
- b+=abs(a)+1;
- if (a<0) a*=-1;
- for (int i=0;i<str;i++){
- for (int j=0;j<stl;j++){
- ar[i][j]=rand()%b-a;
- }
- }
- cout<<endl;
- for (int i=0;i<str;i++){
- for (int j=0;j<stl;j++){
- cout<<ar[i][j]<<" ";
- }
- cout<<endl;
- }
- m=0;
- n=0;
- cout<<endl<<"Вычислим среднее арифметическое. Оно равно ";
- for (int i=0;i<str;i++){
- for (int j=0;j<stl;j++){
- n+=ar[i][j];
- m+=1;}
- }
- n=n/m;
- cout<<n<<endl<<"Изменим массив. Пусть элементы больше среднего арифметического станут равны"<<endl<<"единице, а прочие - нулю";
- for (int i=0;i<str;i++){
- for (int j=0;j<stl;j++){
- if(ar[i][j]>n){
- ar[i][j]=1;}
- else ar[i][j]=0;
- }
- }
- cout<<endl<<"Новый массив"<<endl;
- for (int i=0;i<str;i++){
- for (int j=0;j<stl;j++){
- cout<<ar[i][j]<<" ";
- }
- cout<<endl;
- }
- }
- ---------------------------
- #include <cstdio>
- #include <cstdlib>
- #include <iostream>
- #include <ctime>
- using namespace std;
- int main(){
- srand(time(0));
- setlocale(0,"");
- int n;
- int a;
- int b;
- cout<<"В этой задаче используется квадратная матрица"<<endl
- <<"Введите количество строк / столбцов"<<endl;
- cin>>n;
- const int raz=n;
- int ar[raz][raz];
- cout<<endl<<"Массив будет заполнен случайными числами от..."<<endl;
- cin>>a;
- cout<<endl<<"До..."<<endl;
- cin>>b;
- b+=abs(a)+1;
- if (a<0) a*=-1;
- for (int i=0;i<raz;i++){
- for (int j=0;j<raz;j++){
- ar[i][j]=rand()%b-a;
- }
- }
- cout<<endl;
- for (int i=0;i<raz;i++){
- for (int j=0;j<raz;j++){
- cout<<ar[i][j]<<" ";
- }
- cout<<endl;
- }
- int el = ar[0][1];
- for (int i = 0; i < raz-1; i++){
- for (int j = i+1; j < raz; j++){
- if (ar[i][j] < el) el = ar[i][j];
- }
- }
- cout<<endl<<"Минимальный элемент, среди тех, что стоят выше главной диагонали - "<<el<<endl;
- el = ar[1][0];
- for (int i = 1; i < raz; i++){
- for (int j = 0; j < i; j++){
- if (ar[i][j] > el) el = ar[i][j];
- }
- }
- cout<<endl<<"Максимальный элемент, среди тех, что стоят ниже главной диагонали - "<<el<<endl;
- }
- -------------------------
- #include <cstdio>
- #include <cstdlib>
- #include <iostream>
- #include <ctime>
- using namespace std;
- int main(){
- srand(time(0));
- setlocale(0,"");
- int n;
- int a;
- int b;
- cout<<"В этой задаче используется квадратная матрица"<<endl
- <<"Введите количество строк / столбцов"<<endl;
- cin>>n;
- const int raz=n;
- int ar[raz][raz];
- cout<<endl<<"Массив будет заполнен случайными числами от..."<<endl;
- cin>>a;
- cout<<endl<<"До..."<<endl;
- cin>>b;
- b+=abs(a)+1;
- if (a<0) a*=-1;
- for (int i=0;i<raz;i++){
- for (int j=0;j<raz;j++){
- ar[i][j]=rand()%b-a;
- }
- }
- cout<<endl;
- for (int i=0;i<raz;i++){
- for (int j=0;j<raz;j++){
- cout<<ar[i][j]<<" ";
- }
- cout<<endl;
- }
- int el = ar[0][1];
- for (int i = 0; i < raz-1; i++){
- for (int j = i+1; j < raz; j++){
- if (ar[i][j] < el){
- el = ar[i][j];
- }
- }
- }
- cout<<endl<<"Минимальный элемент, среди тех, что стоят выше главной диагонали - "<<el<<endl<<"Координаты:"<<endl;
- for (int i = 0; i < raz-1; i++){
- for (int j = i+1; j < raz; j++){
- if (ar[i][j] == el){
- cout<<"["<<i+1<<"]["<<j+1<<"]"<<endl;
- }
- }
- }
- el = ar[1][0];
- for (int i = 1; i < raz; i++){
- for (int j = 0; j < i; j++){
- if (ar[i][j] > el) {
- el = ar[i][j];
- }
- }
- }
- cout<<endl<<"Максимальный элемент, среди тех, что стоят ниже главной диагонали - "<<el<<endl<<"Координаты:"<<endl;
- for (int i = 1; i < raz; i++){
- for (int j = 0; j < i; j++){
- if (ar[i][j] == el) {
- cout<<"["<<i+1<<"]["<<j+1<<"]"<<endl;
- }
- }
- }
- }
- ----------------------------
- #include <cstdio>
- #include <cstdlib>
- #include <iostream>
- #include <cmath>
- #include <ctime>
- using namespace std;
- int main(){
- srand(time(0));
- setlocale(0,"");
- int n;
- int m;
- int a;
- int b;
- cout<<"Введите количество строк"<<endl;
- cin>>n;
- cout<<endl<<"Введите количество столбцов"<<endl;
- cin>>m;
- const int str=n;
- const int stl=m;
- int ar[str][stl];
- cout<<endl<<"Массив будет заполнен случайными числами от..."<<endl;
- cin>>a;
- cout<<endl<<"До..."<<endl;
- cin>>b;
- b+=abs(a)+1;
- if (a<0) a*=-1;
- for (int i=0;i<str;i++){
- for (int j=0;j<stl;j++){
- ar[i][j]=rand()%b-a;
- }
- }
- cout<<endl;
- cout<<"Исходный массив"<<endl;
- for (int i=0;i<str;i++){
- for (int j=0;j<stl;j++){
- cout<<ar[i][j]<<" ";
- }
- cout<<endl;
- }
- n=0;
- for (int i=0;i<stl;i++){
- for (int j=0;j<str;j++){
- if ((ar[j][i]%2==0)&&(ar[j][i]!=0)) n+=1;
- }
- cout<<"В "<<i<<" столбце "<<n<<" чётных элементов"<<endl;
- n=0;
- }
- }
- -------------------
- #include <cstdio>
- #include <cstdlib>
- #include <iostream>
- #include <ctime>
- using namespace std;
- int main(){
- srand(time(0));
- setlocale(0,"");
- int n;
- cout<<"В этой задаче используется квадратная матрица"<<endl
- <<"Введите количество строк / столбцов"<<endl;
- cin>>n;
- const int raz=n;
- int ar[raz][raz];
- for (int i=0;i<raz;i++){
- for (int j=0;j<raz;j++){
- if (j==n-i-1) ar[i][j]=1;
- else ar[i][j]=0;
- }
- }
- cout<<endl;
- for (int i=0;i<raz;i++){
- for (int j=0;j<raz;j++){
- cout<<ar[i][j]<<" ";
- }
- cout<<endl;
- }
- }
- -----------------------
- #include <cstdio>
- #include <cstdlib>
- #include <iostream>
- #include <ctime>
- using namespace std;
- int main(){
- srand(time(0));
- setlocale(0,"");
- int n;
- int m;
- int a;
- int b;
- cout<<"Введите количество строк"<<endl;
- cin>>n;
- cout<<endl<<"Введите количество столбцов"<<endl;
- cin>>m;
- const int str=n;
- const int stl=m;
- int ar[str][stl];
- cout<<endl<<"Массив будет заполнен случайными числами от..."<<endl;
- cin>>a;
- cout<<endl<<"До..."<<endl;
- cin>>b;
- b+=abs(a)+1;
- if (a<0) a*=-1;
- for (int i=0;i<str;i++){
- for (int j=0;j<stl;j++){
- ar[i][j]=rand()%b-a;
- }
- }
- cout<<endl;
- for (int i=0;i<str;i++){
- for (int j=0;j<stl;j++){
- cout<<ar[i][j]<<" ";
- }
- cout<<endl;
- }
- n=ar[0][0];
- for (int i=0;i<str;i++){
- for (int j=0;j<stl;j++){
- if (ar[i][j]>n)n=ar[i][j];
- }
- }
- cout<<endl<<"Наибольший элемент массива - "<<n<<endl;
- }
- ----------------------------
- #include <cstdio>
- #include <cstdlib>
- #include <iostream>
- #include <ctime>
- using namespace std;
- int main(){
- srand(time(0));
- setlocale(0,"");
- int n;
- int m;
- int a;
- int b;
- cout<<"Введите количество строк"<<endl;
- cin>>n;
- cout<<endl<<"Введите количество столбцов"<<endl;
- cin>>m;
- const int str=n;
- const int stl=m;
- int ar[str][stl];
- cout<<endl<<"Массив будет заполнен случайными числами от..."<<endl;
- cin>>a;
- cout<<endl<<"До..."<<endl;
- cin>>b;
- b+=abs(a)+1;
- if (a<0) a*=-1;
- for (int i=0;i<str;i++){
- for (int j=0;j<stl;j++){
- ar[i][j]=rand()%b-a;
- }
- }
- cout<<endl;
- for (int i=0;i<str;i++){
- for (int j=0;j<stl;j++){
- cout<<ar[i][j]<<" ";
- }
- cout<<endl;
- }
- n=0;
- m=0;
- for (int i=0;i<str;i++){
- for (int j=0;j<stl;j++){
- if (ar[i][j]%2==0)n+=1;
- }
- if (n>m) {
- m=n;
- a=i;}
- }
- cout<<endl<<"Больше всего четных элементов в "<<a+1<<" строке"<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment