Переведите из паскаля в c++ program p; uses crt; const n = 20; var r: real; a: array[1..n] of integer; i: integer; begin clrscr; randomize; r : = 0; for i : = 1 to n do begin a[i] : = random(50); write(a[i], ' '); r : = r + 1 / a[i]; end; writeln; r : = 1 / r; writeln('r: ', r); readkey; end.
#include <iostream>
#include <windows.h>
#include <conio.h>
#include <ctime>
int main()
{
srand(time(NULL));
const int n = 20;
double r = 0;
int a[n];
system("cls");
for (int i = 0; i < n; i++)
{
a[i] = rand() % 50;
std::cout << a[i] << " ";
r += 1. / a[i];
}
std::cout << std::endl;
r = 1. / r;
std::cout << "R: " << r << std::endl;
getch();
return 0;
}