Печать
Категория: If
Просмотров: 4184

If 04. Даны три целых числа. Найти количество положительных чисел в исходном наборе.

Решение на Python 3

import random

A = random.randrange(-3,3)
B = random.randrange(-3,3)
C = random.randrange(-3,3)
print("Три числа:", A, B, C)

x = 0
if A > 0:
x += 1
if B > 0:
x += 1
if C > 0:
x += 1

print("Количество положительных чисел: ", x)

Решение на C++

#include <bits/stdc++.h>
using namespace std;

int main() {
srand((int)time(0));
int x = 0, A, B, C;
A = rand() % 20 - 10;
B = rand() % 20 - 10;
C = rand() % 20 - 10;
cout << "Number 1: " << A << endl;
cout << "Number 2: " << B << endl;
cout << "Number 3: " << C << endl;

if(A > 0)
x++;
if(B > 0)
x++;
if(C > 0)
x++;

cout << "Positives: " << x << endl;

return 0;
}