Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <iomanip>
- #include <time.h>
- using namespace std;
- int podajn(int &n)
- {
- cout << "Podaj n: ";
- cin>>n;
- }
- void losuj(int n,float *tab)
- {
- for(int i=0;i<n;i++)
- {
- tab[i]=rand()%15 + 2.00;
- cout<<setprecision(3)<<tab[i]<<" ";
- }
- }
- float dodaj(int n,float *tab,float suma)
- {
- suma+=tab[n];
- if(n==0) {return suma;}
- else return dodaj(n-1,tab,suma);
- }
- int main()
- {
- int n;
- podajn(n);
- float *tab;
- tab=new float[n];
- srand(time(NULL));
- losuj(n,tab);
- float suma=0;
- cout<<"Wynik: "<<dodaj(n-1,tab,suma);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement