Advertisement
Guest User

zad7cw12

a guest
Jan 17th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <iomanip>
  4. #include <time.h>
  5. using namespace std;
  6.  
  7. int podajn(int &n)
  8. {
  9. cout << "Podaj n: ";
  10. cin>>n;
  11. }
  12.  
  13. void losuj(int n,float *tab)
  14. {
  15. for(int i=0;i<n;i++)
  16. {
  17. tab[i]=rand()%15 + 2.00;
  18. cout<<setprecision(3)<<tab[i]<<" ";
  19. }
  20. }
  21.  
  22. float dodaj(int n,float *tab,float suma)
  23. {
  24. suma+=tab[n];
  25. if(n==0) {return suma;}
  26. else return dodaj(n-1,tab,suma);
  27. }
  28.  
  29. int main()
  30. {
  31. int n;
  32. podajn(n);
  33. float *tab;
  34. tab=new float[n];
  35. srand(time(NULL));
  36. losuj(n,tab);
  37. float suma=0;
  38. cout<<"Wynik: "<<dodaj(n-1,tab,suma);
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement