Advertisement
alvsjo

Primjer01vjezbe

Oct 13th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void vektor()
  6. {
  7.     int MAX;
  8.     int *niz;
  9.  
  10.     cout << "Unesi velicinu niza" <<endl;
  11.     cin >> MAX;
  12.  
  13.     if (MAX>0)
  14.     {
  15.         niz = new int [MAX];
  16.         for(int i=0;i<MAX;cout <<niz[i++]<<endl);
  17.     }
  18.  
  19.     delete[] niz;
  20. }
  21.  
  22. void viseDimNiz()
  23. {
  24.     int BROJ_VRSTA;
  25.     int BROJ_KOLONA;
  26.     int **a;
  27.  
  28.     cout << "Unesi velicinu vrsta" <<endl;
  29.     cin >> BROJ_VRSTA;
  30.     cout << "Unesi velicinu kolona" <<endl;
  31.     cin >> BROJ_KOLONA;
  32.  
  33.     if (BROJ_VRSTA>0 && BROJ_KOLONA>0)
  34.     {
  35.         a = new int *[BROJ_VRSTA];
  36.         for (int i=0;i<BROJ_VRSTA;i++)
  37.         {
  38.             a[i]= new int [BROJ_KOLONA];
  39.         }
  40.     }
  41.  
  42.  
  43.  
  44. }
  45.  
  46. int main()
  47. {
  48.     int a[10];
  49.     a[0]=111111;
  50.     a[1]=222222;
  51.     a[2]=333333;
  52.  
  53.  
  54.     for(int i=0;i<15;i++) /**< nizovi nemaju prave granice */
  55.         cout <<a[i]<<endl;
  56.    cout << "" << endl;
  57.     cout << a<< "\n" << endl;
  58.      cout << *(a +1) << endl; //aritmetika pokazivaca
  59.  
  60.      int* b =a+1;
  61.      cout << b[0] << "\n"<< endl;
  62.  
  63.     int c[]={100,200,300};
  64.     for (int i=0;i<5;i++)
  65.          cout <<c[i]<<endl;
  66.  
  67.   /**<   for (int i=0;i<3;cout <<c[i++]<<endl);  */
  68.    cout << "" << endl;
  69. vektor();
  70.  
  71.  
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement