Даны два массива x(n) и y(n) . В каком из них больше ненулевых элементов? (НА ЯЗЫКЕ С++)

Ответы

Ответ дал: GreenApelsin
0
#include <iostream>
#include <cstdlib>#include <ctime>
using namespace std;

int main() {
srand(time(0));
const int n = 5;
int x[n], y[n], x0=0, y0=0;
for (int i = 0; i < n; ++i) {
x[i] = rand() % 5;
y[i] = rand() % 5;}
for (int i = 0; i < n; ++i) {
cout<< x[i]<<' ';}
cout << endl;
for (int i = 0; i < n; ++i) {cout << y[i] << ' ';}
for (int i = 0; i < n; ++i) {
if (x[i]) x0++;
if (y[i]) y0++;}
cout << endl;
if (x0 > y0) cout << 'x';
if (x0 < y0) cout << 'y';
if (x0 == y0) cout << '='; 
return 0;}
Вас заинтересует