Advertisement
PatrickSwayze

zad 8 roz 12

Jan 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include<iostream> ///////ZAD8/////
  2. #include<ctime>
  3. #include<cstdlib>
  4. #include<windows.h>
  5. #include<iomanip>
  6. using namespace std;
  7. int pobierz_n(int &n)
  8. {
  9.   cout<<"Podaj n"<<endl;
  10.   cin>>n;
  11. }
  12. int wypelnij_tablice(float **tab, int n)
  13. {
  14.     for(int i=0;i<n;i++)
  15.     {
  16.         for(int j=0;j<n;j++)
  17.         {
  18.             if(j<=i)
  19.             tab[i][j]=rand()/(RAND_MAX+1.0)*9+1;
  20.             else tab[i][j]=0;
  21.         }
  22.     }
  23. }
  24. void wypisz(float **tab, int n)
  25. {
  26.     cout<<endl;
  27.      for(int i=0;i<n;i++)
  28.     {
  29.         for(int j=0;j<n;j++)
  30.         {
  31.             cout.width(4);
  32.             cout<<setprecision(3)<<tab[i][j]<<" ";
  33.         }
  34.             cout<<endl<<endl;
  35.     }
  36. }
  37. int kopiuj(float **tab,int n)
  38. {
  39.     int g;
  40.     for(int i=0;i<n;i++)
  41.     {
  42.         for(int j=0;j<n;j++)
  43.         {
  44.         tab[n-j-1][n-i-1]=tab[n-i-1][n-j-1];
  45.         }
  46.     }
  47. }
  48. int main()
  49. {
  50.     srand(time(NULL));
  51. int n;
  52. pobierz_n(n);
  53.  
  54. float **tablica=new float*[n];
  55. for(int i=0;i<n;i++)
  56. tablica[i]= new float[n];
  57.  
  58. wypelnij_tablice(tablica,n);
  59. wypisz(tablica,n);
  60. kopiuj(tablica,n);
  61. wypisz(tablica,n);
  62. return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement