Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 4th, 2012  |  syntax: C++  |  size: 0.65 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4.  
  5.  
  6. using namespace std;
  7. int *Stepeni(int n)
  8. {
  9.     int*niz=new int[n];
  10.     if (n<=0) throw "Broj elemenata mora biti pozitivan";
  11.     try
  12.     {
  13.         for (int i=0; i<n; i++)
  14.         {
  15.             niz[i]=pow(2.0,i+1);
  16.         }
  17.         return niz;
  18.  
  19.     }
  20.     catch (...)
  21.     {
  22.  
  23.         throw "Alokacija nije uspjela!";
  24.     }
  25. }
  26.  
  27. int main()
  28. {
  29.  
  30.     int n;
  31.  
  32.     try
  33.     {
  34.         cin>>n;
  35.         int *niz(Stepeni(n));
  36.         for (int i=0; i<n; i++)
  37.             cout<<niz[i]<<" ";
  38.         delete [] niz;
  39.     }
  40.     catch (char poruka[])
  41.     {
  42.         cout<<poruka;
  43.     }
  44.  
  45.  
  46.     return 0;
  47. }