Помогите написать программу на C#

Discussion in 'С/С++, C#, Rust, Swift, Go, Java, Perl, Ruby' started by HelpMeeeee, 1 Apr 2016.

  1. HelpMeeeee

    HelpMeeeee New Member

    Joined:
    1 Apr 2016
    Messages:
    1
    Likes Received:
    0
    Reputations:
    0
    Вот сама задача:
    Напишите программу, которая после введенного с клавиатуры числа (от 1 до 999), дописывает слово «рубль» в правильной
    форме (21 рубль, 332 рубля, 890 рублей)
     
  2. Kaimi

    Kaimi Well-Known Member

    Joined:
    23 Aug 2007
    Messages:
    1,732
    Likes Received:
    811
    Reputations:
    231
    Сам перепиши на C#
    Code:
    <?php
    
    echo declOfNum(21, array('рубль', 'рубля', 'рублей'));
    echo "\n";
    echo declOfNum(332, array('рубль', 'рубля', 'рублей'));
    echo "\n";
    echo declOfNum(890, array('рубль', 'рубля', 'рублей'));
    
    function declOfNum($number, $titles)
    {
    $cases = array (2, 0, 1, 1, 1, 2);
    return $number." ".$titles[ ($number%100 > 4 && $number %100 < 20) ? 2 : $cases[min($number%10, 5)] ];
    }
    
     
    _________________________
  3. maza-in

    maza-in New Member

    Joined:
    6 Feb 2016
    Messages:
    8
    Likes Received:
    2
    Reputations:
    0
    Вот, держи!

    На форму кинь Button и Textbox

    Code:
    private void button1_Click(object sender, EventArgs e)
            {
                string s= textBox1.Text;
                string ss = textBox1.Text.Substring(textBox1.Text.Length - 1, 1);
                string sss = "";
                int iii=0;
    
                if (textBox1.Text.Length >= 2)
                {
                   sss = textBox1.Text.Substring(textBox1.Text.Length - 2, 2);
                   iii = Convert.ToInt32(sss);
                }
                        
                int ii = Convert.ToInt32(ss);
                int i = Convert.ToInt32(s);
                       
                if (ii == 1)
                    { textBox1.Text = s + " рубль"; }
    
                if ((ii >= 2) && (ii <= 4))
                    { textBox1.Text = s + " рубля"; }
    
                if ((ii >= 5) && (ii <= 9) || (ii == 0))
                    { textBox1.Text = s + " рублей"; }
    
                if (iii != 0)
                    {
                    if ((iii >= 11) && (iii <= 14))
                        { textBox1.Text = s + " рублей"; }
                    }
            }
     
    #3 maza-in, 1 Apr 2016
    Last edited: 1 Apr 2016
    marynli likes this.
  4. SooLFaa

    SooLFaa Members of Antichat

    Joined:
    17 Mar 2014
    Messages:
    530
    Likes Received:
    499
    Reputations:
    154
    Есть уже полно готовых склонятелей. В том числе есть библиотека от Ts-Soft.
     
    _________________________
    The_Doc likes this.
Loading...
Similar Threads - Помогите написать программу
  1. Peja
    Replies:
    0
    Views:
    2,547