Guest User

Untitled

a guest
Oct 23rd, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3.  
  4. using namespace std;
  5. int slad(int a);
  6. int main()
  7. {
  8.     int c;
  9.     cout<<"obliczanie sladu macierzy"<<endl;
  10.     cout<<"podaj rozmiar macierzy"<<endl;
  11.     int a;
  12.     cin>>a;
  13.     c=slad(a);
  14.     cout<<"Slad macierzy = "<<c;
  15.  
  16.  
  17.     getch();
  18. }
  19. int slad(int a)
  20. {
  21.     int wynik=0;
  22.     int **tab;
  23.     tab=new int*[a];
  24.     for(int i=0;i<a;i++)
  25.     {
  26.         tab[i]=new int[a];
  27.     }
  28.     cout<<"wypelnij macierz liczbami:"<<endl;
  29.     for(int i=0;i<a;i++)
  30.     {
  31.         for(int j=0;j<a;j++)
  32.         {
  33.             cin>>tab[i][j];
  34.         }
  35.     }
  36.     cout<<"wypelniona macierz"<<endl;
  37.     for(int i=0;i<a;i++)
  38.     {
  39.         for(int j=0;j<a;j++)
  40.         {
  41.             cout<<tab[i][j]<<" ";
  42.         }
  43.         cout<<endl;
  44.     }
  45.    
  46.     for(int i=0;i<a;i++)
  47.     {
  48.         for(int j=0;j<a;j++)
  49.         {
  50.             if(i==j)
  51.             {
  52.                 wynik+=tab[i][j];
  53.             }
  54.         }
  55.     }
  56.  
  57.     return wynik;
  58. }
Add Comment
Please, Sign In to add comment