#include <iostream> #include <string> int main() { using namespace std;
//1й пункт string s1 = "Computer programming (often shortened to programming) is a process"; for (int i = 2; i < s1.size(); i = i + 3) cout << s1[i]; cout << endl;
//2й пункт string s2 = "Programming involves activities such as analysis, developing understanding"; for (int i = 1; i < s2.size(); i = i + 2) if (s2[i] != 'a' && s2[i] != 'b') s2[i] = 'a'; else s2[i] = 'c'; cout << s2 << endl;
Procedure convert ( x: integer ); var s: string; k, error, len: integer; element: array[1..20] of real; i, rez: real; const N = -2; begin s := IntToStr(x); len := length(s); if len = 0 then writeln('Ошибка!') else begin i := 0; rez := 0; for k := 1 to len do val(s[k], element[k], error); for k := 1 to len do begin i := element[k] * power( N, len - k ); rez := rez + i; end; writeln(rez); end; end;
var numeric: integer; begin write('Введите двоичное число для перевода в систему счисления с основанием (-2): '); readln(numeric); write('ответ: '); convert(numeric); end.
#include <string>
int main()
{
using namespace std;
//1й пункт
string s1 = "Computer programming (often shortened to programming) is a process";
for (int i = 2; i < s1.size(); i = i + 3)
cout << s1[i];
cout << endl;
//2й пункт
string s2 = "Programming involves activities such as analysis, developing understanding";
for (int i = 1; i < s2.size(); i = i + 2)
if (s2[i] != 'a' && s2[i] != 'b')
s2[i] = 'a';
else
s2[i] = 'c';
cout << s2 << endl;
return 0;
}
var s: string;
k, error, len: integer;
element: array[1..20] of real;
i, rez: real;
const N = -2;
begin
s := IntToStr(x);
len := length(s);
if len = 0 then writeln('Ошибка!')
else
begin i := 0;
rez := 0;
for k := 1 to len do val(s[k], element[k], error);
for k := 1 to len do
begin
i := element[k] * power( N, len - k );
rez := rez + i;
end;
writeln(rez);
end;
end;
var numeric: integer;
begin
write('Введите двоичное число для перевода в систему счисления с основанием (-2): ');
readln(numeric);
write('ответ: ');
convert(numeric);
end.