Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <math.h>
- #include "iomanip"
- double sr(int n, int* a);
- int maximum(int *arr, int n);
- void posl(int *arr, int n, int m);
- using namespace std;
- int _tmain(int argc, _TCHAR* argv[])
- {
- setlocale( LC_ALL,"Russian" );
- int n,i,m;
- cout << "Введите размер: ";
- cin >> n;
- int* arr = new int[n];
- cout << "Введите массив: ";
- for (i=0; i<n; i++)
- cin >> arr[i];
- cout << "Среднее арифетическое массива: " << sr(n,arr) << endl;
- cout << "Номер максимального элемета массива: " << maximum(arr,n) << endl;
- m=maximum(arr,n);
- cout << "Массив после удаления: ";
- posl(arr,n,m);
- cout << endl;
- system("pause");
- return 0;
- }
- double sr(int n, int* arr)
- {
- int sum = 0;
- for (int i=0; i<n; i++)
- sum+=arr[i];
- return sum/n;
- }
- int maximum(int *arr, int n)
- {
- int max,k=0;
- max = arr[0];
- for(int i=0; i<n; i++)
- {
- if(arr[i]>max)
- {
- max = arr[i];
- k=i+1;
- }
- }
- return k;
- }
- void posl(int *arr, int n, int m)
- {
- int* arr1 = new int[n];
- int d=0,k;
- for (k=0;k<m;k++)
- {
- arr1[d]=arr[k];
- cout << arr1[d] << setw(2);
- d++;
- }
- for (k=m;k<n;k++)
- {
- if (arr[k] == 1)
- {
- arr1[d]=arr[k];
- cout << arr1[d] << setw(2);
- d++;
- }
- float end = sqrt((float)arr[k]);
- for (int i=2; i <= end; i++)
- if (arr[k]%i == 0)
- {
- arr1[d]=arr[k];
- cout << arr1[d] << setw(2);
- d++;
- }
- }
- int sum1 = 0;
- for (int i1=0; i1<d; i1++)
- sum1+=arr1[i1];
- cout <<endl<<"Cреднее арифетическое массива после удаления: "<< sum1/d;
- }
Advertisement
Add Comment
Please, Sign In to add comment