1. k (K>1) butun soni berilgen. S=1+1/2-1/3+1/4-…+(-1) K*1/K yig`indini hisoblovchi Sum(K,S) funksiyasini tuzing. Bu yerda s – kiuvchi/chiquvchi parametr. Console. Write("k="); int k = int. Parse
N elementdan iborat yaxlit sonlar massivi berilgan. Ushbu massivda tub sonlar sonin aniqlovchi sinf metodi tuzilsin
Download 23.83 Kb.
|
algoritim
32. N elementdan iborat yaxlit sonlar massivi berilgan. Ushbu massivda tub sonlar sonin aniqlovchi sinf metodi tuzilsin.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace ConsoleApplication1{class Program{ static bool TubSon(int a){bool t; for (int i = 2; i <= a / 2; i++){if (a % i != 0) t = true;else{t = false; return false; }}return true; } static void Main(string[] args){ int n = int.Parse(Console.ReadLine());int[] a = new int[n]; int s=0;for (int i = 0; i < n; i++){ Console.Write("a[" + i + "]=");a[i] = int.Parse( Console.ReadLine());if (TubSon(a[i])) s++; }Console.WriteLine(s) Console.ReadKey(); }}} _______________________________________________________________________________________________________________________________ №33. Matnli faylda S satri va C simvolı berilgan. S qatorida C simvolı qatnashmagan so'zlardi aniqlovchi dastur tuzilsin. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace ConsoleApplication1{class Program{ static void Main(string[] args){ StreamReader uqish = new StreamReader("g:\\uqish.txt");string[] s = uqish.ReadLine().Split(' '); char c = char.Parse(uqish.ReadLine());for (int i = 0; i < s.Length; i++){if (s[i].Split(c).Length == 1) Console.WriteLine(s[i]); } uqish.Close(); Console.ReadKey(); }}} _______________________________________________________________________________________________________________________________ №34. MxN ikkita o'lchamli haqiqiy sonlar massivi berilgan. Ko'paytmasi eng katta bo'lgan satr raqamini aniqlovchi sinf metodi tuzilsin using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace ConsoleApplication1{class Program{ static void Main(string[] args){ int m = int.Parse(Console.ReadLine());int n = int.Parse(Console.ReadLine()); double[,] mas= new double[m, n]; for (int i = 0; i < m; i++){for (int j = 0; j < n; j++){mas[i, j] = double.Parse(Console.ReadLine());}}double min=0,ind=0; for (int i = 0; i < m; i++){double s = 1; for (int j = 0; j < n; j++){s *= mas[i, j]; }if (i == 0) min = s; else if (s < min) { min = s; ind = i; }}Console.WriteLine(ind); Console.ReadKey(); }}} _______________________________________________________________________________________________________________________________ №35.A haqiqiy soni va N yaxlit soni (N>0) berilgan. Bitta tsikldan foydalanib, S=1-(A+1) + (A+2)^2 – (A+3)^3 …+(-1)^n*(A+n)^N ifodaning ma'nosini hisoblashchi So'm(A, N, S) funkciyası tuzilsin. Bu yerda S - kiruvshi/chiquvchi parametr. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1{ class Program { static double Som(double a,int n,ref double s){ int i; s=1;for (i = 0; i < n; ++i){s += Math.Pow(-1, n) * Math.Pow(a + n, n); }return s; }static void Main(string[] args){ double a = double.Parse(Console.ReadLine());int n = int.Parse(Console.ReadLine());double s = 1; Som(a,n,ref s); Console.WriteLine(s); Console.ReadKey(); } } } ________________________________________________________________________________________________________________________________ №45.X va Y sonlaridan kichigini X ga kattasini Y ga yozuvchi Minmax (X, Y) sinf metodini tuzing. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1{ class Program {static void Minmax(ref double x,ref double y){double a=y; if (x>y) { y = x; x = a; }}static void Main(string[] args){double x = double.Parse(Console.ReadLine()); double y = double.Parse(Console.ReadLine());Minmax(ref x,ref y);Console.WriteLine(x); Console.WriteLine(y); Console.ReadKey();} } } Download 23.83 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling