Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <cstdlib>
- #include <iostream>
- #include <iomanip>
- #include <clocale>
- #include <cmath>
- using namespace std;
- void input(float *a, int n){
- for (int i = 0; i < n; i++){
- cout << i << ": ";
- cin >> a[i];
- }
- }
- void output(float *a, int n){
- for (int i = 0; i < n; i++){
- cout << setw(4) << a[i];
- }
- cout << endl;
- }
- int min(float *a, int n){
- float min = abs(a[0]);
- int num=0;
- for (int i = 1; i < n; i++){
- if (min > abs(a[i])){
- min = abs(a[i]);
- num = i;
- }
- }
- return num;
- }
- int max(float *a, int n){
- float max = abs(a[0]);
- int num = 0;
- for (int i = 1; i < n; i++){
- if (max < abs(a[i])){
- max = abs(a[i]);
- num=i;
- }
- }
- return num;
- }
- float pr(float *a, int n){
- float ppp = 1;
- bool flag = 1;
- int max_n = max(a, n), min_n = min(a, n);
- if (max_n < min_n)
- swap(max_n, min_n);
- for (int i = min_n + 1; i < max_n; i++){
- ppp *= a[i];
- flag = 0;
- }
- if (flag)
- ppp = 0;
- return ppp;
- }
- void sort(float *a, int n){
- for (int i = 0; i < n; i++){
- for (int j = n-1; j>i; j--){
- if (a[j-1] < a[j]){
- float tmp = a[j];
- a[j] = a[j-1];
- a[j-1] = tmp;
- }
- }
- }
- }
- float sum(float *a, int n){
- float s = 0;
- for (int i = 0; i < n; i++){
- if (a[i]>0)
- s += a[i];
- }
- return s;
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- setlocale(LC_ALL, "rus");
- int n;
- cin >> n;
- float *a = new float[n];
- input(a, n);
- cout << endl;
- cout << "Исходный массив:" << endl;
- output(a, n);
- cout << "Сумма положительных элементов: " << sum(a, n)<<endl;
- cout << "Произведение: " << pr(a, n)<<endl;
- sort(a, n);
- cout << "Отсортированный массив:"<< endl;
- output(a, n);
- cout << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement