#include <iostream>
#include <time.h>
#include <stdlib.h>
#include <iomanip>
using namespace std;
int main() {
srand(time(0));
int count =0;
int array;
int b,a;
int N;
cout << " Diapazon ";
cin >> a >> b;
cout << " Input count element ";
cin >> N;
for(int i=0;i<N;i++)
{
array=rand()% a + b;
if(array >=0)
count ++;
}
cout << array << setw(5);
cout << endl;
cout << " Count = "<< count << endl;
Программа:
Python:
from random import randint
arr = [randint(-20, 20) for i in range(0, 10)]
print(arr)
n = 0
for i in arr:
if i > 0:
n += 1
print(n)
#include <iostream>
#include <time.h>
#include <stdlib.h>
#include <iomanip>
using namespace std;
int main() {
srand(time(0));
int count =0;
int array;
int b,a;
int N;
cout << " Diapazon ";
cin >> a >> b;
cout << " Input count element ";
cin >> N;
for(int i=0;i<N;i++)
{
array=rand()% a + b;
if(array >=0)
{
count ++;
}
cout << array << setw(5);
}
cout << endl;
cout << " Count = "<< count << endl;
}
Программа:
Python:
from random import randint
arr = [randint(-20, 20) for i in range(0, 10)]
print(arr)
n = 0
for i in arr:
if i > 0:
n += 1
print(n)