Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <ctime>
- using namespace std;
- void wypelnij(int **tab,int n,int m)
- {
- for(int i=0; i<n; i++)
- {
- for(int j=0; j<m; j++)
- {
- tab[i][j]=rand()%10;
- }
- }
- }
- void wyswietl(int** tab,int n,int m)
- {
- for(int i=0; i<n; i++)
- {
- cout<<endl;
- for(int j=0; j<m; j++)
- {
- cout<<tab[i][j]<<" ";
- }
- }
- }
- void suma(int **tab,int n,int m,int wybor=0)
- {
- int suma=0;int maxx=0;int indeks=0;
- if(wybor==0)
- {
- for(int i=0;i<n;i++)
- {
- suma=0;
- for(int j=0;j<m;j++)
- {
- suma+=tab[i][j];
- }
- if(suma>maxx)
- {
- maxx=suma;
- indeks=i;
- }
- }
- cout<<"Max="<<maxx<<" w wierszu nr: "<<indeks<<endl;
- }
- else
- {
- int suma=0;int maxx=0;int indeks=0;
- for(int j=0;j<m;j++)
- {
- suma=0;
- for(int i=0;i<n;i++)
- {
- suma+=tab[i][j];
- }
- if(suma>maxx)
- {
- maxx=suma;
- indeks=j;
- }
- }
- cout<<"Max="<<maxx<<" w kolumnie nr: "<<indeks<<endl;
- }
- }
- int main()
- {
- srand((time(NULL)));
- int n,m;
- cout<<"Podaj n: ";
- cin>>n;
- cout<<"Podaj m: ";
- cin>>m;
- int **tablica;
- tablica=new int*[n];
- for(int i=0; i<n;i++)
- tablica[i]=new int[m];
- wypelnij(tablica,n,m);
- wyswietl(tablica,n,m);
- cout<<endl;
- suma(tablica,n,m);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement