' QBASIC CONST n = 10 DIM a(1 TO n) AS DOUBLE, b(1 TO n) AS DOUBLE, x(1 TO n) AS DOUBLE RANDOMIZE TIMER CLS FOR i = 1 TO n a(i) = 50 * RND - 25 b(i) = 50 * RND - 25 IF a(i) <> 0 THEN x(i) = b(i) / a(i) ELSE x(i) = 0 END IF PRINT USING "###."; a(i); PRINT " * "; PRINT USING "###."; x(i); PRINT " = "; PRINT USING "###."; b(i) NEXT i
#include <iostream>
#include <string>
#include <conio.h>
#define ESC 27
using namespace std;
int main() {
char ch;
int sum = 0;
do {
ch = _getch();
if (ch == ESC) {
cout << "Output of the program:\n" << sum;
putchar('\n');
} else {
cout << ch;
sum += (int)ch;
putchar('\n');
}
} while (ch != ESC);
system("pause");
return 0;
}
Объяснение:
CONST n = 10
DIM a(1 TO n) AS DOUBLE, b(1 TO n) AS DOUBLE, x(1 TO n) AS DOUBLE
RANDOMIZE TIMER
CLS
FOR i = 1 TO n
a(i) = 50 * RND - 25
b(i) = 50 * RND - 25
IF a(i) <> 0 THEN
x(i) = b(i) / a(i)
ELSE
x(i) = 0
END IF
PRINT USING "###."; a(i);
PRINT " * ";
PRINT USING "###."; x(i);
PRINT " = ";
PRINT USING "###."; b(i)
NEXT i
Тестовое решение:
-14.65854 * 0.53867 = -7.89606
-14.19729 * 1.08311 = -15.37722
-17.21156 * -0.07488 = 1.28888
16.17024 * -1.09750 = -17.74690
-13.80126 * -1.06180 = 14.65417
17.78583 * 0.83055 = 14.77207
-10.95534 * -1.58899 = 17.40791
-11.84992 * 1.66222 = -19.69714
-24.91831 * -0.95948 = 23.90864
-12.68757 * 0.84160 = -10.67785