M
Miller85
Не могу запрограмировать... Помогите плиз...
Исходная матрица (4*5)
2 0 3 -4 5
1 -2 7 -3 0
0 4 -5 -6 -2
6 9 5 2 -1
Вот мой код
Исходная матрица (4*5)
2 0 3 -4 5
1 -2 7 -3 0
0 4 -5 -6 -2
6 9 5 2 -1
Вот мой код
C++:
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
#include<stdlib.h>
void main(void)
{
int x[4][5],n,m,i,j,k,q,s,mi,mj;
char ch;
unsigned int b;
clrscr();
cout<<"VVedite rasmeri ishodnoi matrici"<<endl
<<"kolichestvo strok(<=4):";
cin>>n;
cout<<"kolichestvo stolbcov(<=5):";
cin>>m;
cout<<"Vvedite 1, esli matrica vvoditsya vruchnuy,"<<endl
<<"ili luboy drugoi simvol, esli ona formiruetsya"<<endl
<<"datchikom cluchaynih chisel:";
cin>>ch;
if(ch=='1'){
cout<<"Vvedite ishodnuy matricu iz celih chisel"<<endl;
for(i=0;i<n;i++)
for(j=0;j<m;j++)
{cout<<"x["<<i<<"]["<<j<<"]=";
cin>>x[i][j];}
}
else{
cout<<"Vvedite celoe pologitelnoe chislo"<<endl
<<"dlya inicializacii datchika"<<endl
<<"sluchaynix chisel:";
cin>>b;
srand(b);
for(i=0;i<n;i++)
for(j=0;j<m;j++)x[i][j]=(rand()-16383)%10;
}
cout<<endl<<endl<<endl<<setw(30)<<"Ishodnaya matrica:"<<endl;
for(i=0;i<n;i++)
{for(j=0;j<m;j++)cout<<setw(6)<<x[i][j];
cout<<endl;
}
k=0;q=0;mi=0;mj=0;
for(j=0;j<m;j++){
mj=0;
for(i=0;i<n;i++)
if(x[i][j]>x[mi][mj]){mi=i;mj=j;}
}
if(mi==0)cout<<"maximalnih elementov v matrice net"<<endl;
else{
cout<<endl<<"kolichestvo maximalnih pologitelinih elementov v matrice - "<<mi
<< " v "
<<q<< "-m stolbce"<<endl;
cout<<endl<<setw(30)<<"poluchen massiv:"<<endl;
for(i=0;i<n;i++)cout<<setw(6)<<x[i][q];
cout<<endl;
}
cout<<endl<<"konec programmi.";
getch();
}