Игорь Пашев

Dec. 6th, 2010

04:19 pm

Каюсь, грешен.
Наибольший общий делитель нескольких чисел на C#.

Использование:
# gmcs gcd.cs
# mono ./gcd.exe 121 11 33 44
11
# mono ./gcd.exe 2 4 6 8
2


 1 using System;
 2
 3 namespace GCD {
 4     class Program {
 5         static uint gcd2(uint a, uint b) {
 6             uint c;
 7             while (b != 0) {
 8                 c = b;
 9                 b = a % b;
10                 a = c;
11             }
12             return a;
13         }
14
15         static uint gcdn(uint [] n) {
16             uint r = n[0];
17             for (int i = 1; i < n.Length; i++)
18                 r = gcd2(r, n[i]);
19             return r;
20         }
21
22         static void Main(string [] argv) {
23             uint [] a = Array.ConvertAll<string, uint>(argv,
24                     new Converter<string, uint>
25                     (delegate(string s) {return uint.Parse(s);})
26                     );
27
28             Console.WriteLine("{0}", gcdn(a));
29         }
30     }
31 }
32

Tags: , ,
(Оставить комментарий)

Jan. 17th, 2009

08:06 pm

mono 2.2

./mono.slackbuild
...
checking for valgrind/memcheck.h... no
checking if the Mono Debugger is supported on this platform... no
checking if the tls_model attribute is supported... yes
./configure: line 40437: syntax error near unexpected token `('
./configure: line 40437: `  for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do'


Ну как так?

Tags:
(2 комментария | Оставить комментарий)

Nov. 2nd, 2008

06:39 pm - Mono

Скомпилировал и поставил Mono 2.0.1.

Взял из Википедии пример (файл h.cs):

class Example
{
    static void Main()
    {
        System.Console.WriteLine("Hello, World!");
    }
}


Скомпилировал: mcs h.cs
Получил h.exe (3,0K)
Запустил: mono h.exe
Увидел: Hello, World!

Т. е. работает. Непонятно только почему включаемые файлы запихались в /usr/include/mono-1.

Tags: ,
(Оставить комментарий)