Прошу на C++
Дан массив ненулевых целых чисел. Определить, сколько раз элементы
массива при просмотре от его начала меняют знак. Например, в массиве 10,
-4, 12, -4, -89, знак меняется три раза.
Прошу на C++
Ответы на вопрос
Ответил Mishka28
0
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{
srand (time(NULL));
int a[10],k = 0;
for (int i = 0; i<10; i++)
{
do
{
a[i] = rand()%20-10;
}
while (a[i]==0);
cout <<a[i] <<" ";
}
cout <<endl;
for (int i = 0; i<9; i++)
if ((a[i]>0 && a[i+1]<0) || (a[i]<0 && a[i+1]>0))
++k;
cout <<"Kol-vo: " <<k <<endl;
return 0;
}
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{
srand (time(NULL));
int a[10],k = 0;
for (int i = 0; i<10; i++)
{
do
{
a[i] = rand()%20-10;
}
while (a[i]==0);
cout <<a[i] <<" ";
}
cout <<endl;
for (int i = 0; i<9; i++)
if ((a[i]>0 && a[i+1]<0) || (a[i]<0 && a[i+1]>0))
++k;
cout <<"Kol-vo: " <<k <<endl;
return 0;
}
Новые вопросы