//Школьный вариант Var s:string; p:real; se:set of char; i:integer; begin readln(s); se:=['0','1','2','3','4','5','6','7','8','9']; for i:=1 to length(s) do if s[i] in se then begin p:=p+1; write(s[i]); end; p:=p/(length(s)/100); writeln; writeln('Percent=',p); end.
//Альтернативный вариант Var s:string; se:set of char; begin readln(s); se:=['0','1','2','3','4','5','6','7','8','9']; s.Where(x -> x in se).Println; writeln('Percent=',s.where(x -> x in se).Count/(length(s)/100)); end.
Пример ввода: I3artle, Caster, 1 of 7 summoned characters. Пример вывода: 317 Percent=6.81818181818182
//Школьный вариант
Var
s:string;
p:real;
se:set of char;
i:integer;
begin
readln(s);
se:=['0','1','2','3','4','5','6','7','8','9'];
for i:=1 to length(s) do
if s[i] in se then
begin
p:=p+1;
write(s[i]);
end;
p:=p/(length(s)/100);
writeln;
writeln('Percent=',p);
end.
//Альтернативный вариант
Var
s:string;
se:set of char;
begin
readln(s);
se:=['0','1','2','3','4','5','6','7','8','9'];
s.Where(x -> x in se).Println;
writeln('Percent=',s.where(x -> x in se).Count/(length(s)/100));
end.
Пример ввода:
I3artle, Caster, 1 of 7 summoned characters.
Пример вывода:
317
Percent=6.81818181818182
class Program
{
static void Main()
{
var random = new Random(DateTime.Now.Millisecond);
var n = random.Next(5, 10);
var matrix = new int[n, n];
for (var i = 0; i < matrix.GetLength(0); i++)
{
for (var j = 0; j < matrix.GetLength(1); j++)
{
matrix[i, j] = random.Next(0, 9);
Console.Write(matrix[i, j] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
Console.WriteLine("Sum = {0}", SumAboveMainDiagonal(matrix));
Console.ReadKey();
}
static int SumAboveMainDiagonal(int[,] m)
{
var sum = 0;
Console.WriteLine("Summing elements:");
for (var i = 0; i < m.GetLength(0); i++)
{
for (var j = 0; j < m.GetLength(1); j++)
{
if (i < j)
{
sum += m[i, j];
Console.Write(m[i, j] + " ");
}
else { Console.Write(0 + " "); }
}
Console.WriteLine();
}
return sum;
}
}