#include "stdafx.h"//del
#include <iostream>
#include <iomanip>
#include "windows.h"
using namespace std;
const int N = 15;
void printMenu()
{
cout << "Select action: " <<endl;
cout << "1. Fill and print" << endl;
cout << "2. Arithmetic mean of negative elements" << endl;
cout << "3. Arithmetic mean of positive elements" << endl;
cout << "0. Exit" << endl;
}
int main()
{
int *pMas = new int[N]; //столбцы
for (int i = 0; i < N; i++)
pMas[i] = 0;
int flag = -1;
while (true)
{
system("cls");
printMenu();
int answ = -1;
cout << "N = "; cin >> answ;
switch (answ)
{
case 1:
{
flag = 1;
for (int i = 0; i < N; i++)
pMas[i] = -100 + rand() % 200;
for (int i = 0; i < N; i++)
cout << "mas["<<i<<"]= " << pMas[i] << endl;
system("pause");
break;
}
case 2:
{
if (flag == -1) { cout << "No array!" << endl; system("pause");}
int sum = 0, tempM = 0;
for (int i = 0; i < N; i++)
{
if (pMas[i] < 0)
{
tempM++;
sum = sum + pMas[i];
}
}
double result = sum / double(tempM);
cout << "Arithmetic mean of negative elements = " << result << endl;
system("pause");
break;
}
case 3:
{
if (flag == -1) { cout << "No array!" << endl; system("pause"); }
int sum = 0, tempM = 0;
for (int i = 0; i < N; i++)
{
if (pMas[i] > 0)
{
tempM++;
sum = sum + pMas[i];
}
}
double result = sum / double(tempM);
cout << "Arithmetic mean of positive elements = " << result << endl;
system("pause");
break;
}
case 0:
{
exit(1);
break;
}
default:
cout << "Re-enter!!!" << endl;
system("pause");
}
}
delete[] pMas;
return 0;
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.