Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <math.h>
- double sr(int n, int* a);
- double srr(int n, int* a);
- using namespace std;
- int _tmain(int argc, _TCHAR* argv[])
- {
- int n,i;
- cout << "vvedite razmer: ";
- cin >> n;
- int* a = new int[n];
- cout << "vvedite massiv: ";
- for (i=0; i<n; i++)
- cin >> a[i];
- cout << "sredn (ne rekurs) = " << sr(n,a) << endl;
- cout << "sredn (rekurs) = " << srr(n,a)/n << endl;
- system("pause");
- return 0;
- }
- double sr(int n, int* a)
- {
- int sum = 0;
- for (int i=0; i<n; i++)
- sum+=a[i];
- return sum/n;
- }
- double srr(int n, int* a)
- {
- if (n==1) return a[0];
- else return srr(n-1,a)+a[n-1];
- }
Advertisement
Add Comment
Please, Sign In to add comment