Class Program { static int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
static void Main() { Console.Write("N = "); int n = int.Parse(Console.ReadLine()); int s = 0, p = 1, c = 0; while (n > 0) { s += n % 10; p *= n % 10; n /= 10; c++; }
// Вторая задача Console.Write("P = "); int P = int.Parse(Console.ReadLine()); Console.Write("Q = "); int Q = int.Parse(Console.ReadLine()); for (int i = 2; i <= 1 + 2*(int)Math.Sqrt(P); i++) { if (Q % i == 0 && gcd(P, i) == 1) Console.Write(i + " "); } Console.ReadLine(); } }
Var a: array of integer; i, n: integer; begin randomize; n := Random(10) + 1; SetLength(a, n); writeln('Исходный массив'); for i := 0 to n-1 do begin a[i] := Random(10); write(a[i]:5, ' '); end; writeln;
writeln('Возвести в квадрат'); for i := 0 to n-1 do begin a[i] := sqr(a[i]); write (a[i]:5, ' '); end; writeln;
writeln('Заполнить степенями 2'); a[n-1] := 1; for i := n-2 downto 0 do a[i] := a[i+1] shl 1;
for i := 0 to n-1 do write (a[i]:5, ' '); writeln;
writeln ('умножить на 3 во второй половине'); for i := n shr 1 to n-1 do a[i] := (a[i] shl 1) + a[i];
for i := 0 to n-1 do write (a[i]:5, ' '); writeln; end.
{
static int gcd(int a, int b)
{
return b == 0 ? a : gcd(b, a % b);
}
static void Main()
{
Console.Write("N = ");
int n = int.Parse(Console.ReadLine());
int s = 0, p = 1, c = 0;
while (n > 0)
{
s += n % 10;
p *= n % 10;
n /= 10;
c++;
}
Console.WriteLine("Произведение: {0}", p);
Console.WriteLine("Сумма: {0}", p);
Console.WriteLine("Среднее: {0}", (double)s/c);
// Вторая задача
Console.Write("P = ");
int P = int.Parse(Console.ReadLine());
Console.Write("Q = ");
int Q = int.Parse(Console.ReadLine());
for (int i = 2; i <= 1 + 2*(int)Math.Sqrt(P); i++)
{
if (Q % i == 0 && gcd(P, i) == 1)
Console.Write(i + " ");
}
Console.ReadLine();
}
}
a: array of integer;
i, n: integer;
begin
randomize;
n := Random(10) + 1;
SetLength(a, n);
writeln('Исходный массив');
for i := 0 to n-1 do begin
a[i] := Random(10);
write(a[i]:5, ' ');
end; writeln;
writeln('Возвести в квадрат');
for i := 0 to n-1 do begin
a[i] := sqr(a[i]);
write (a[i]:5, ' ');
end; writeln;
writeln('Заполнить степенями 2');
a[n-1] := 1;
for i := n-2 downto 0 do
a[i] := a[i+1] shl 1;
for i := 0 to n-1 do write (a[i]:5, ' ');
writeln;
writeln ('умножить на 3 во второй половине');
for i := n shr 1 to n-1 do
a[i] := (a[i] shl 1) + a[i];
for i := 0 to n-1 do write (a[i]:5, ' ');
writeln;
end.