Close
c_sharp_wordmark-svg

C# (C sharp) [si sharp] – dasturlash tili bo’yicha qisqacha darslar

  1. MAX va MIN raqamlarini funksiya orqali topish:
  1. using System;
  2.  
  3.  
  4.  
  5. namespace Numbers
  6.  
  7. {
  8.  
  9.    class Max
  10.  
  11.    {
  12.  
  13.        public static int MaxFunc(int[] n)
  14.  
  15.        {
  16.  
  17.            int num = n[0] ;
  18.  
  19.           
  20.  
  21.            for (int i = 0; i < n.Length; i++)
  22.  
  23.            {
  24.  
  25.                if (num < n[i])
  26.  
  27.                    num = n[i];
  28.  
  29.                }
  30.  
  31.            return num;
  32.  
  33.        }
  34.  
  35.  
  36.  
  37.        public static int MinFunc(int[] n)
  38.  
  39.        {
  40.  
  41.            int min = n[0];
  42.  
  43.  
  44.  
  45.            for (int i = 0; i < n.Length; i++)
  46.  
  47.            {
  48.  
  49.                if (min > n[i])
  50.  
  51.                    min = n[i];
  52.  
  53.            }
  54.  
  55.            return min;
  56.  
  57.        }
  58.  
  59.  
  60.  
  61.        static void Main(string[] args)
  62.  
  63.            {
  64.  
  65.            int[] numbers = { -1, -3, -5, -6, -7, -7, -8 };
  66.  
  67.            
  68.  
  69.            int max = Max.MaxFunc(numbers);
  70.  
  71.            int min = Max.MinFunc(numbers);
  72.  
  73.  
  74.  
  75.            Console.WriteLine("Max number is {0}", max);
  76.  
  77.            Console.WriteLine("Min number is {0}", min);
  78.  
  79.            Console.ReadKey();
  80.  
  81.            }
  82.  
  83.        }
  84.  
  85.    }

 

  1. Max raqamni topish:
  1. using System;
  2.  
  3.  
  4.  
  5. namespace Numbers
  6.  
  7. {
  8.  
  9.    class Max
  10.  
  11.    {
  12.  
  13.        static void Main(string[] args)
  14.  
  15.        {
  16.  
  17.            int Max = 0;
  18.  
  19.            int[] numbers = { 4, 54, 434, 34, 23 };
  20.  
  21.            
  22.  
  23.            for (int i = 0; i < numbers.Length; i++)
  24.  
  25.            {
  26.  
  27.                if (Max < numbers[i])
  28.  
  29.                    Max = numbers[i];
  30.  
  31.  
  32.  
  33.                Console.Write(" {0},", numbers[i]);
  34.  
  35.            
  36.  
  37.            }
  38.  
  39.            Console.WriteLine("\n {0}", Max);
  40.  
  41.            Console.ReadKey();
  42.  
  43.       }
  44.  
  45.    }
  46.  
  47. }

 

  1. So’zlarning orasidagi bo’sh joylar sonini aniqlash.
using System;
 
 
 
namespace P1
 
{
 
   class Program
 
   {
 
       static void Main(string[] args)
 
       {
 
           string input = "Dot Net Perls website";
 
           int spaces = 0;
 
           for (int i = 0; i < input.Length; i++)
 
           {
 
               if (input[i] == ' ')
 
               {
 
                   spaces++;
 
               }
 
 
 
           }
 
           Console.WriteLine(spaces);
 
           Console.ReadKey();
 
           }
 
}
 
}

 

(820 marta o'qilgan, bugun 1 marta o'qildi)

O'xshash maqolalar:

Leave a Reply

Your email address will not be published. Required fields are marked *