// PascalABC.NET 3.2, сборка 1478 от 10.06.2017 // Внимание! Если программа не работает, обновите версию!
№1
function Swp(Self:array of real):sequence of real; extensionmethod; begin foreach var x in Self do begin var s:=x.ToString; var p:=Pos('.',s); Swap(s[p-2],s[p-1]); Swap(s[p+1],s[p+2]); yield s.ToReal end end;
begin var a:=SeqRandom(25,3700000,9000000).Select(x->x/1000).ToArray; a.Println; a.Swp.Println end.
function F(Self:array of integer):sequence of string; extensionmethod; begin foreach var m in Self do begin var (i,k,s):=(m,0,0); while i<>0 do begin var d:=i mod 10; s+=d; k+=1; i:=i div 10 end; yield m+' '+m.ToString.Inverse+' k='+k+', s='+s end end;
begin ArrRandom(20,50,25000).F.Println(NewLine) end.
function DMS(Self:array of real):sequence of string; extensionmethod; begin foreach var x in Self do begin var g:=Trunc(x); var t:=Frac(x)*60; var m:=Trunc(t); var s:=Round(Frac(t)*60); if s=60 then (m,s):=(m+1,0); yield g+'^'+m++s+'"' end end;
begin var a:=SeqRandom(30,0,36000).Select(x->x/100).ToArray; a.Println; a.DMS.Println end.
public class Test
{
public static int change(int x){return -x;}
public static void Main()
{
const int n=5;
int[,] a=new int[n,n];
Random rnd=new Random();
Console.Write("введите число:");
int c=int.Parse(Console.ReadLine());
Console.WriteLine("");
Console.WriteLine("исходный массив:");
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
a[i,j]=rnd.Next(1,10);
Console.Write(a[i,j]);
}
Console.WriteLine("");
}
Console.WriteLine("полученный массив:");
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(a[i,j]==c) a[i,j]=change(c);
Console.Write(a[i,j]);
}
Console.WriteLine("");
}
}
}
// Внимание! Если программа не работает, обновите версию!
№1
function Swp(Self:array of real):sequence of real; extensionmethod;
begin
foreach var x in Self do begin
var s:=x.ToString;
var p:=Pos('.',s);
Swap(s[p-2],s[p-1]); Swap(s[p+1],s[p+2]);
yield s.ToReal
end
end;
begin
var a:=SeqRandom(25,3700000,9000000).Select(x->x/1000).ToArray;
a.Println; a.Swp.Println
end.
Пример
7523.959 7162.231 5141.402 8185.317 6123.038 5675.867 6710.577 7232.389 5076.099 7174.131 3805.721 6247.679 4859.791 7234.724 8596.392 6104.583 8676.872 8835.96 3862.549 8718.651 6409.72 5529.988 7028.17 5118.341 7680.518
7532.599 7126.321 5114.042 8158.137 6132.308 5657.687 6701.757 7223.839 5067.909 7147.311 3850.271 6274.769 4895.971 7243.274 8569.932 6140.853 8667.782 8853.69 3826.459 8781.561 6490.27 5592.898 7082.71 5181.431 7608.158
№2
function F(Self:array of integer):sequence of string;
extensionmethod;
begin
foreach var m in Self do begin
var (i,k,s):=(m,0,0);
while i<>0 do begin
var d:=i mod 10;
s+=d; k+=1;
i:=i div 10
end;
yield m+' '+m.ToString.Inverse+' k='+k+', s='+s
end
end;
begin
ArrRandom(20,50,25000).F.Println(NewLine)
end.
Пример
21183 38112 k=5, s=15
2840 0482 k=4, s=14
18397 79381 k=5, s=28
1852 2581 k=4, s=16
12844 44821 k=5, s=19
16749 94761 k=5, s=27
12366 66321 k=5, s=18
7603 3067 k=4, s=16
22472 27422 k=5, s=17
2569 9652 k=4, s=22
9893 3989 k=4, s=29
8648 8468 k=4, s=26
2182 2812 k=4, s=13
15769 96751 k=5, s=28
1800 0081 k=4, s=9
14343 34341 k=5, s=15
21030 03012 k=5, s=6
13545 54531 k=5, s=18
11942 24911 k=5, s=17
21695 59612 k=5, s=23
№3
function DMS(Self:array of real):sequence of string; extensionmethod;
begin
foreach var x in Self do begin
var g:=Trunc(x);
var t:=Frac(x)*60;
var m:=Trunc(t);
var s:=Round(Frac(t)*60);
if s=60 then (m,s):=(m+1,0);
yield g+'^'+m++s+'"'
end
end;
begin
var a:=SeqRandom(30,0,36000).Select(x->x/100).ToArray;
a.Println; a.DMS.Println
end.
Пример
322.82 85.26 90.26 340.37 239.69 192.67 184.99 243.02 229.13 218.63 319.76 143.79 120.41 343.85 340.58 309.83 159.38 298.8 91.11 235.01 227.81 37.14 159.01 67.35 256.18 356.7 5.16 17.14 261.35 25.8
322^49'12" 85^15'36" 90^15'36" 340^22'12" 239^41'24" 192^40'12" 184^59'24" 243^1'12" 229^7'48" 218^37'48" 319^45'36" 143^47'24" 120^24'36" 343^51'0" 340^34'48" 309^49'48" 159^22'48" 298^48'0" 91^6'36" 235^0'36" 227^48'36" 37^8'24" 159^0'36" 67^21'0" 256^10'48" 356^42'0" 5^9'36" 17^8'24" 261^21'0" 25^48'0"