Бағдарлама коды берілген. OUTPUT “1 ден 10-ға дейінгі сан енгізіңіз” INPUT Number IF Number < 5 THEN OUTPUT Number + “бұл кіші сан” ELSE OUTPUT Number + “бұл үлкен сан” ENDIF Бағдарламаның орындалу ретін жазыңыз.
На третьей строчке, видимо, ошибка, и вместо Вывод(x) на самом деле Ввод(x).
var x: integer; y: real; begin Readln(x); y := (10 + 2 * x) / (11 - x); Writeln(y); end.При x = 3 переменная y = 2Задание 3var number, resultNumber, i: integer; begin resultNumber := 1; for i := 1 to 3 do begin Readln(number); resultNumber := resultNumber * number; end; Writeln(resultNumber); end.Задание 4var a: integer; b, c: real; begin a := 3; b := -1.5; c := 6 - 2 * b; c := c - a; Writeln(c); end.Результатом вывода будет число 6Задание 5var x, y, z: integer; begin x := 8; y := 2; if (x > y) then z := x - y else z := y + x; Writeln(z); end.
#include <iostream>
// матрица 2 на 2// a b// c dtemplate< typename T = int >class matrix2{public: T a, b, c, d;
matrix2() : a(0), b(0), c(0), d(0) {} matrix2(T a, T b, T c, T d) : a(a), b(b), c(c), d(d) {}
matrix2 & operator *= (matrix2 & other) { T ta, tb, tc, td; ta = a * other.a + b * other.c; tb = a * other.b + b * other.d; tc = a * other.c + c * other.d; td = b * other.c + d * other.d; a = ta, b = tb, c = tc, d = td; }
matrix2 operator * (matrix2 & other) { T ta, tb, tc, td; ta = a * other.a + b * other.c; tb = a * other.b + b * other.d; tc = a * other.c + c * other.d; td = b * other.c + d * other.d; return matrix2(ta, tb, tc, td); }
matrix2 pow(int power) { matrix2 result(1, 0, 0, 1); matrix2 cur = *this; while (power) { if (power & 1) { power ^= 1; result *= cur; } else { power >>= 1; cur *= cur; } } return result; }
void operator = (matrix2 other) { a = other.a; b = other.b; c = other.c; d = other.d; }
friend std::ostream & operator << (std::ostream & ostr, matrix2 ma) { ostr << std::endl; ostr << ma.a << " " << ma.b << std::endl; ostr << ma.c << " " << ma.d << std::endl; return ostr; }
};
int main(void){ matrix2< int > m1(1, 1, 1, 0), tmp;
const int N = 12;
std::cout << m1.pow(N).a;
return 0;}
На третьей строчке, видимо, ошибка, и вместо Вывод(x) на самом деле Ввод(x).
var x: integer; y: real; begin Readln(x); y := (10 + 2 * x) / (11 - x); Writeln(y); end.При x = 3 переменная y = 2Задание 3var number, resultNumber, i: integer; begin resultNumber := 1; for i := 1 to 3 do begin Readln(number); resultNumber := resultNumber * number; end; Writeln(resultNumber); end.Задание 4var a: integer; b, c: real; begin a := 3; b := -1.5; c := 6 - 2 * b; c := c - a; Writeln(c); end.Результатом вывода будет число 6Задание 5var x, y, z: integer; begin x := 8; y := 2; if (x > y) then z := x - y else z := y + x; Writeln(z); end.