A guruh talabasi Rahimboyev Muhiddinning
Download 57.14 Kb.
|
D.T.L.I. Rahimboyev Muhiddin
- Bu sahifa navigatsiya:
- 7- laboratoriya ishi
6- laboratoriya ishi
6-varyant
using System; namespace ConsoleApp { class Program { static void Main(string[] args) { int n = 10; // n ni o'zgartirib ketma-ketlik yig'indisini hisoblayishingiz mumkin double sum = 0; for (int k = 0; k <= n; k++) { double numerator = Math.Pow(-1, k); double denominator = Factorial(2 * k); double term = numerator / denominator; sum += term; } Console.WriteLine("Birinchi {0} ta hadning yig'indisi: {1}", n, sum); } static double Factorial(int n) { double result = 1; for (int i = 2; i <= n; i++) { result *= i; } return result; } } } 7- laboratoriya ishi 6-varyant Satr berilgan. Abc harflari guruhi unga necha marta kiritilganligini aniqlang. using System; using System.Windows.Forms; namespace StringExample { public partial class Form1 : Form { public Form1() { InitializeComponent(); string myString = "abcabcaabcabcbbabc"; int count = 0; int index = myString.IndexOf("abc"); while (index != -1) { count++; index = myString.IndexOf("abc", index + 1); } string resultString = string.Format("Matnda 'abc' harflari guruhi {0} marta kiritilgan.", count); TextBox textBox = new TextBox(); textBox.Multiline = true; textBox.ReadOnly = true; textBox.Text = resultString; this.Controls.Add(textBox); textBox.Dock = DockStyle.Fill; } } } Matn rus tilida berilgan. Unda eng qisqa so'z necha marta uchrashini aniqlang. using System; using System.Linq; using System.Windows.Forms; namespace StringExample { public partial class Form1 : Form { public Form1() { InitializeComponent(); string myString = "Это тестовая строка для проверки, что слово может появиться только один раз. Эта строка также содержит повторяющиеся слова, такие как слово и строка."; // Matndan so'zlar ro'yxatini olib chiqamiz string[] words = myString.Split(new char[] { ' ', ',', '.', '!', '?', ':', ';', '-' }, StringSplitOptions.RemoveEmptyEntries); // So'zlar uzunligi bo'yicha saralab, eng qisqa so'zni olib chiqamiz string shortestWord = words.OrderBy(word => word.Length).FirstOrDefault(); // Eng qisqa so'z uchun necha marta uchrashganligini hisoblaymiz int count = words.Count(word => word == shortestWord); // Natijani matn ko'rinishida chiqaramiz string resultString = string.Format("Eng qisqa so'z: {0}\nUchrashganligi: {1}", shortestWord, count); // Matnni ko'rsatish uchun TextBox yaratamiz va unga natijani o'tkazamiz TextBox textBox = new TextBox(); textBox.Multiline = true; textBox.ReadOnly = true; textBox.Text = resultString; // TextBoxni Formga qo'shamiz this.Controls.Add(textBox); textBox.Dock = DockStyle.Fill; } } } a Å b shaklidagi arifmetik ifodalar uchraydigan matn berilgan, bu erda Å +, -, *, / belgilaridan biridir. Barcha arifmetik ifodalarni yozing va ularning qiymatlarini hisoblang. using System; using System.Windows.Forms; namespace StringExample { public partial class Form1 : Form { public Form1() { InitializeComponent(); string myString = "a*b+c/d-a"; double a = 2.5; double b = 3.7; double c = 1.2; double d = 4.6; double result = EvaluateExpression(myString, a, b, c, d); string resultString = string.Format("{0} = {1}", myString, result); TextBox textBox = new TextBox(); textBox.Multiline = true; textBox.ReadOnly = true; textBox.Text = resultString; this.Controls.Add(textBox); textBox.Dock = DockStyle.Fill; } static double EvaluateExpression(string expression, double a, double b, double c, double d) { // Å belgisini arifmetik amallar bilan almashtiramiz expression = expression.Replace("Å", "+"); expression = expression.Replace("-", "+-"); // Matndan barcha arifmetik ifodalarni olib chiqamiz string[] terms = expression.Split(new char[] { '+' }); double result = 0; foreach (string term in terms) { // Arifmetik ifoda ichidagi o'zgaruvchilarni qiymatlariga o'zgartiramiz string processedTerm = term.Replace("a", a.ToString()); processedTerm = processedTerm.Replace("b", b.ToString()); processedTerm = processedTerm.Replace("c", c.ToString()); processedTerm = processedTerm.Replace("d", d.ToString()); // O'zgaruvchilarga qiymatlar o'zgartirilgan ifodani hisoblaymiz double termResult = EvaluateTerm(processedTerm); // Jami natijani hisoblaymiz result += termResult; } return result; } static double EvaluateTerm(string term) { // Matndagi ifodani hisoblaymiz try { return Convert.ToDouble(term); } catch (FormatException) { // Matnda xatolik bo'lsa 0 qaytarib chiqamiz return 0; } } } } Download 57.14 Kb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling