Упорядочить специальным образом массив. Сдвинуть все отрицательные элементы влево, нули в центр, положительные элементы вправо, не меняя места

#include "stdafx.h"

#include <iostream>

#include <cmath>

#include <ctime>

#include <cstdlib>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])

{

int a [10000], n;

cin >> n;

for (int i=0; i<n; i++)

{

a[i] = rand () % 10-5;

cout << a[i] << " ";

}

cout << endl;

for (int k=0;k<n; k++)

for (int i=0; i<n-1; i++)

if (a[i] > 0 && a[i+1] <= 0 || a[i] == 0 && a[i+1] < 0)

swap (a[i], a[i+1]);

for (int i=0; i<n; i++)

cout << a[i] << " ";

cout << endl;

system ("pause");

return 0;

}

 

 

Определить в каждой ли строке матрицы есть хотя бы один нулевой элемент

#include "stdafx.h"

#include <iostream>

#include <iomanip>

#include <cstdlib>

#include <ctime>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])

{

const int N =3;

int a[N][N];

srand (time (0));

for (int i=0; i < N; i++)

for (int j=0; j < N; j++)

a[i][j] = rand () % 2;

for (int i=0; i < N; i++)

{

for (int j = 0; j < N; j++)

cout << setw(4) << a[i][j];

cout << endl;

}

bool ok;

for (int i = 0; i < N; i++)

{

ok = false;

for (int j = 0; j < N; j++)

if (a[i][j] == 0)

{

ok = true;

break;

}

if (! ok)

break;

}

if (ok)

cout << "Yes" << endl;

else

cout << "No" << endl;

system ("pause");

return 0;

}


Понравилась статья? Добавь ее в закладку (CTRL+D) и не забудь поделиться с друзьями:  



double arrow
Сейчас читают про: