16.09.2012, 15:52. Просмотров 395. Ответов 1
Произведение элементов в тех строках, которые не содержат отрицательных элементов
Не получается.
//---------------------------------------------------------------------------------------------------------
C++ |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
| //-------------------------------------
// _36_.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "iostream"
#include "conio.h"
#include "iomanip"
#include "ctime"
using namespace std;
//--------------------------------------------
void rand(int **arr, int n, int m)
{
srand(time(NULL));
for(int i = 0; i < n; i++)
{
for(int j = 0; j < m; j++)
{
arr[i][j] = rand() % 5 - 1;
}
}
}
//--------------------------------------------
void print(int **arr, int n, int m)
{
for(int i = 0; i < n; i++)
{
for(int j = 0; j < m; j++)
{
cout << setw(3) << *(*(arr + i) + j);
}
cout << "\n\n";
}
cout << "-------------------------------------------------\n\n";
}
//--------------------------------------------
bool matrica(int *arr, int n)
{
for(int i = 0; i < n; i++)
{
if(arr[i] < 0)
return true;
}
return false;
}
//--------------------------------------------
int _tmain(int argc, _TCHAR* argv[])
{
setlocale(0,"");
int n, m, **arr;
n = m = 0;
cout << "Введите размер строк: ";
cin >> n;
cout << "\n\nВведите размер столбцов: ";
cin >> m;
arr = new int*[n];
for(int i = 0; i < n; i++)
*(arr + i) = new int[m];
cout << "\n\nМатрица имеет вид: \n\n";
rand(arr,n,m);
print(arr,n,m);
int k = 0;
int count = 0, pr = 1;
for(int i = 0; i < n; i++)
{
if(matrica(arr[i],n) == 0)
{
count++;
}
}
cout << "\n\nКоличество строк в которых нет отрицательных элементов: " << count;
cout << "\n\n" << pr;
for(int i = 0; i < n; i++)
delete []arr[i];
delete[] arr;
_getch();
return 0;
} |
|