Public double Sum(int k, ref double S)
Download 46.38 Kb.
|
Algoritm jb
1. internal class SumOff { public double Sum(int k, ref double S) { double m = k; while (m > 1) { S += (double)(Math.Pow(-1, m) * (1 / m)); m--; } return S; } } static void Main(string[] args) { int k = Convert.ToInt32(Console.ReadLine()); double S = 1; SumOff q = new SumOff(); Console.WriteLine(q.Sum(k, ref S)); Console.ReadLine(); } 2. internal class WordsCount { public void Words(string gap) { string[] massiv = gap.Split(); Console.WriteLine(massiv.Length); } } internal class Program { static void Main(string[] args) { WordsCount q = new WordsCount(); string a = File.ReadAllText("d:\\Word.txt"); q.Words(a); Console.ReadLine(); } } 3. internal class Apiwayi_san { public bool PrimeNumber(int a, ref bool t) { int sum = 0; if (a != 2 && a % 2 == 0 || a == 1) { t = false; } else { for (int i = 1; i <= a; i++) { if (a % i == 0) { sum++; } } if (sum > 2) { t = false; } else { t = true; } } return t; } } static void Main(string[] args) { bool t = false; int a = Convert.ToInt32(Console.ReadLine()); Apiwayi_san q = new Apiwayi_san(); Console.WriteLine(q.PrimeNumber(a, ref t)); Console.ReadLine(); } 4.
{ public void Upper(string gap) { int sum = 0; int sum2 = 0; string[] D = gap.Split(); for (int i = 0; i < D.Length; i++) { for (int j = 0; j < D[i].Length; j++) { if (D[i][j] >= 'A' && D[i][j] <= 'Z' || D[i][j] >= 'А' && D[i][j] <= 'Я') { sum++; } } if (sum > 0) { sum2++; } sum = 0; } Console.WriteLine(sum2); } } static void Main(string[] args) { Upperword p = new Upperword(); string q = File.ReadAllText("d:\\Word.txt"); p.Upper(q); Console.ReadLine(); } 5.
{ public bool PowerABP(int a, int b, int p) { return p == Math.Pow(a, b); } } static void Main(string[] args) { int a = Convert.ToInt32(Console.ReadLine()); int b = Convert.ToInt32(Console.ReadLine()); int p = Convert.ToInt32(Console.ReadLine()); Power q = new Power(); Console.WriteLine(q.PowerABP(a, b, p)); } 6. internal class UpperWords { public void Upper(string gap) { int sum = 0; int sum2 = 0; string[] D = gap.Split(); for (int i = 0; i < D.Length; i++) { for (int j = 0; j < D[i].Length; j++) { if (D[i][j] >= 'A' && D[i][j] <= 'Z' || D[i][j] >= 'А' && D[i][j] <= 'Я') { sum++; } } if (sum == D[i].Length) { sum2++; } sum = 0; } Console.WriteLine(sum2); } } static void Main(string[] args) { UpperWords m = new UpperWords(); string p = File.ReadAllText("d:\\Word.txt"); m.Upper(p); Console.ReadLine(); } 7.
{ int m; int n; double[,] a; public int M { get { return m; } set { m = value; } } public int N { get { return n; } set { n = value; } } public void Create_matrix() { a = new double[m, n]; Random r = new Random(); Console.WriteLine("Matrica elementlerin kiritin': "); for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) a[i, j] = r.Next(0, 100); } public void Print_matrix() { Console.WriteLine("Matrica : "); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) Console.Write("\t" + a[i, j]); Console.WriteLine(); } } public void OddnumberIndex() { int numdercol = -1; for (int j = 0; j < n; j++) { bool odd = true; for (int i = 0; i < m; i++) { if (a[i,j] % 2 == 0) odd = false; } if (odd) { numdercol = j; break; } } Console.WriteLine(numdercol); } } static void Main(string[] args) { Matrix ob = new Matrix(); Console.Write("M = "); ob.M = Convert.ToInt32(Console.ReadLine()); Console.Write("N = "); ob.N = Convert.ToInt32(Console.ReadLine()); ob.Create_matrix(); ob.Print_matrix(); ob.OddnumberIndex(); Console.ReadLine(); } 8.
{ public void Perfect(int a) { int sum = 0; for (int i = 1; i <= a; i++) { if (a % i == 0) { sum++; } } if (sum > 2) { Console.WriteLine(1); } else { Console.WriteLine(0); }
static void Main(string[] args)
9.
{ public int osiw(int[,] mat,int m,int n) { int result = -1; int[] ar = new int[m]; int san; for (int i = n-1; i >=0; i--) { san = 0; for (int j = 0; j < m; j++) { ar[j] = Convert.ToInt32(mat[j, i]); } Array.Sort(ar); for (int j = 0; j < m; j++) { if (Convert.ToInt32(ar[j]) != Convert.ToInt32(mat[j, i])) { break; } else { san++; } } if (san==m) { result = i; break; } } return result+1; } } static void Main(string[] args) { Console.WriteLine("Matrica olshemin kiriting:"); int m = Convert.ToInt32(Console.ReadLine()); int n = Convert.ToInt32(Console.ReadLine()); int[,] matrica = new int[m, n]; Console.WriteLine("Matrica elementlerin kiritemiz: "); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { matrica[i, j] = Convert.ToInt32(Console.ReadLine()); } } Console.WriteLine(""); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { Console.Write( matrica[i, j]+" " ); } Console.WriteLine(""); } Matrix mat = new Matrix(); Console.WriteLine(mat.osiw(matrica, m, n)); Console.ReadLine(); } 10.
{ public void Prime(int A) { int primenumber = 0; for (int i = 2; i < A; i++) { primenumber = Check(i); } Console.Write(primenumber); } public int Check(int a) { int sum = 0; for (int i = 1; i <= a; i++) { if (a % i == 0) { sum++; } } if (sum == 2) { return a; } else { return 0; } } } static void Main(string[] args) { string s = File.ReadAllText("d:\\Word.txt"); int a = Convert.ToInt32(s); MaxPrime q = new MaxPrime(); q.Prime(a); Console.ReadLine(); } 11.
{ int m; int n; double[,] a; public int M { get { return m; } set { m = value; } } public int N { get { return n; } set { n = value; } } public void Create_matrix() { a = new double[m, n]; Random r = new Random(); Console.WriteLine("Matrica elementlerin kiritin': "); for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) a[i, j] = r.Next(0, 100); } public void Print_matrix() { Console.WriteLine("Matrica : "); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) Console.Write("\t" + a[i, j]); Console.WriteLine(); } } public void Zero() { int numdercol = -1; for (int j = 0; j < n; j++) { bool odd = false; for (int i = 0; i < m; i++) { if (a[i, j] == 0) odd = true; } if (odd) { numdercol = j; break; } } Console.WriteLine(numdercol); } } static void Main(string[] args) { Matrix ob = new Matrix(); Console.Write("M = "); ob.M = Convert.ToInt32(Console.ReadLine()); Console.Write("N = "); ob.N = Convert.ToInt32(Console.ReadLine()); ob.Create_matrix(); ob.Print_matrix(); ob.Zero(); Console.ReadLine(); } 12.
{ public double Sum(int n, ref double s) { for (double i = 2; i <= n; i++) { s += ((i - 1) / i); } return s; } } static void Main(string[] args) { int n = Convert.ToInt32(Console.ReadLine()); double s = 1; SumOff q = new SumOff(); Console.WriteLine(q.Sum(n, ref s)); Console.ReadLine(); } 13.
{ long n; public string S { get; set; } public void Read_number() { string path1 = "d:\\Word.txt"; using (StreamReader reader = new StreamReader(path1)) { string text = reader.ReadToEnd(); n = Convert.ToInt64(text); } } public void Convert_2to10() { string path2 = "d:\\Convert_number.txt"; string text = n.ToString(); using (StreamWriter writer = new StreamWriter(path2)) { int a = 0, j = 0; for (int i = 0; i < text.Length; i++) { a+= ((int)(text[i]) - 48) * (int)Math.Pow(2, text.Length-1-j); j++; } writer.Write(a); } } } static void Main(string[] args) { Twoconvertten ob = new Twoconvertten(); ob.Read_number(); ob.Convert_2to10(); Console.ReadLine(); } 14.
{ int m; int n; int[,] a; public int M { get { return m; } set { m = value; } } public int N { get { return n; } set { n = value; } } public void Create_matrix() { a = new int[m, n]; Random r = new Random(); Console.WriteLine("Matrica elementlerin kiritin': "); for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) a[i, j] = r.Next(0, 100); } public void Print_matrix() { Console.WriteLine("Matrica : "); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) Console.Write("\t" + a[i, j]); Console.WriteLine(); } } public void NotZero() { int count = 0; for (int j = 0; j < n; j++) { bool odd = true; for (int i = 0; i < m; i++) { if (a[i, j] == 0) odd = false; } if (odd) { count++; } } Console.WriteLine(count); } } static void Main(string[] args) { Matrix ob = new Matrix(); Console.Write("M = "); ob.M = Convert.ToInt32(Console.ReadLine()); Console.Write("N = "); ob.N = Convert.ToInt32(Console.ReadLine()); ob.Create_matrix(); ob.Print_matrix(); ob.NotZero(); Console.ReadLine(); } 15.
{ public bool isSquare(int k, ref bool t) { double x = Math.Round(Math.Sqrt(k)); t = (x * x == k); return t; } } static void Main(string[] args) { bool t = true; int k = Convert.ToInt32(Console.ReadLine()); Degree q = new Degree(); Console.WriteLine(q.isSquare(k,ref t)); Console.ReadLine(); } 16.
{ public void natiyje(int n1,int n2,string f) { string[] d = f.Split('\n'); string s1 = d[0]; string s2 = d[1]; string s = ""; for (int i = 0; i < n1; i++) { s += s1[i]; } s += " "; for (int i = s2.Length - n2; i < s2.Length; i++) { s += s2[i]; } Console.WriteLine(s); } } static void Main(string[] args) { int n1 = Convert.ToInt32(Console.ReadLine()); int n2 = Convert.ToInt32(Console.ReadLine()); string gap = File.ReadAllText("d:\\Word.txt"); Split_num obj = new Split_num(); obj.natiyje(n1,n2,gap); } 17.
{ public double Sum(double a, int n, ref double s) { for (int i = 1; i <= n; i++) { s += Math.Pow(-1, i) * Math.Pow(a, i); } return s; } } static void Main(string[] args) { double s = 1; double a = Convert.ToDouble(Console.ReadLine()); int n = Convert.ToInt32(Console.ReadLine()); SumOff q = new SumOff(); Console.WriteLine(q.Sum(a, n, ref s)); Console.ReadLine(); } 18.
{ public void Eight_to_two(string s) { string n = Convert.ToString(Convert.ToInt64(s, 8), 2); Console.WriteLine(n); } } static void Main(string[] args) { string s = File.ReadAllText("d:\\Word.txt"); _8_to_2 q = new _8_to_2(); q.Eight_to_two(s); Console.ReadLine(); } 19.
{ public void ekilik(string s) { string binary = Convert.ToString(Convert.ToInt32(s, 16), 2); Console.WriteLine(binary); } } static void Main(string[] args) { string s = File.ReadAllText("d:\\Word.txt"); Convert_16 q = new Convert_16(); q.ekilik(s); Console.ReadLine(); } 20.
{ public int Fibonacci(int n, int san) { int a1 = 1; int b1 = 1; for (int i = 2; i < n; i++) { san = a1 + b1; a1 = b1; b1 = san; } return san; } } static void Main(string[] args) { int n =Convert.ToInt32(Console.ReadLine()); int a = 0; Fibonachi q = new Fibonachi(); Console.WriteLine(q.Fibonacci(n, a)); Console.ReadLine(); } 21.
{ public int[,] osiw(int[,] mat, int m, int n) { int[] ar = new int[m]; for (int i = 0; i for (int j = 0; j < m; j++) { ar[j] = Convert.ToInt32(mat[j, i]); } Array.Sort(ar); for (int j = 0; j < m; j++) { mat[j, i] = ar[j]; } }
return mat; } } static void Main(string[] args) { Console.WriteLine("Matrica olshemin kiriting:"); int m = Convert.ToInt32(Console.ReadLine()); int n = Convert.ToInt32(Console.ReadLine()); int[,] matrica = new int[m, n]; Console.WriteLine("Matrica elementlerin kiritemiz: "); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { matrica[i, j] = Convert.ToInt32(Console.ReadLine()); } } Console.WriteLine(""); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { Console.Write( matrica[i, j]+" " ); } Console.WriteLine(""); } Console.WriteLine(" "); Matrix mat = new Matrix(); matrica = mat.osiw(matrica, m, n); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { Console.Write(matrica[i, j] + " "); } Console.WriteLine(""); } Console.ReadLine(); } 22. class Matrix { public int[,] osiw(int[,] mat, int m, int n) { int[] ar = new int[n]; int min=0, max=0; for (int i =0; i < m; i++) { for (int j = 0; j < n; j++) { ar[j] = Convert.ToInt32(mat[i, j]); } Array.Sort(ar); min = ar[0]; max = ar[n - 1]; for (int j = 0; j < n; j++) { if (mat[i,j]==min) { mat[i, j] = max; } else if(mat[i,j]==max) { mat[i, j] = min; } } }
} } static void Main(string[] args) { Console.WriteLine("Matrica olshemin kiriting:"); int m = Convert.ToInt32(Console.ReadLine()); int n = Convert.ToInt32(Console.ReadLine()); int[,] matrica = new int[m, n]; Console.WriteLine("Matrica elementlerin kiritemiz: "); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { matrica[i, j] = Convert.ToInt32(Console.ReadLine()); } } Console.WriteLine(""); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { Console.Write(matrica[i, j] + " "); } Console.WriteLine(""); } Console.WriteLine(" "); Matrix mat = new Matrix(); matrica = mat.osiw(matrica, m, n); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { Console.Write(matrica[i, j] + " "); } Console.WriteLine(""); } Console.ReadLine(); } 23.
{ public void Count_three(string s) { string[] p = s.Split(); int sum = 0; for (int i = 0; i < p.Length; i++) { for (int j = 0; j < p[i].Length; j++) { if (p[i][j] == 'a') { sum++; } } if (sum == 3) { Console.WriteLine(p[i]); } sum = 0; } } } static void Main(string[] args) { string s = File.ReadAllText("d:\\Word.txt"); Count q = new Count(); q.Count_three(s); Console.ReadLine(); } 24.
{ int m; int n; double[,] a; public int M { get { return m; } set { m = value; } } public int N { get { return n; } set { n = value; } } public void Create_matrix() { a = new double[m, n]; Random r = new Random(); Console.WriteLine("Matrica elementlerin kiritin': "); for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) a[i, j] = r.Next(0, 100); } public void Print_matrix() { Console.WriteLine("Matrica : "); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) Console.Write("\t" + a[i, j]); Console.WriteLine(); } } public void Min() { double min = 0, index = 0; for (int i = 0; i < m; i++) { double s = 1; for (int j = 0; j < n; j++) { s *= a[i, j]; } if (i == 0) min = s; else if (s < min) { min = s; index = i; } } Console.WriteLine(index); } } static void Main(string[] args) { MinumString ob = new MinumString(); Console.Write("M = "); ob.M = Convert.ToInt32(Console.ReadLine()); Console.Write("N = "); ob.N = Convert.ToInt32(Console.ReadLine()); ob.Create_matrix(); ob.Print_matrix(); ob.Min(); Console.ReadLine(); } 25.
{ public void Delete(string s,string s1) { if (s.IndexOf(s1) > 0) { Console.WriteLine(s.Remove(s.IndexOf(s1), s1.Length)); } else { Console.WriteLine(s); } } } static void Main(string[] args) { StreamReader read = new StreamReader("d:\\Word.txt"); string s = read.ReadLine(); string s1 = read.ReadLine(); Delet q = new Delet(); q.Delete(s,s1); read.Close(); Console.ReadKey(); } 26.
{ public void Cons(int n) { int[] a = new int[n]; int[] b = new int[n]; int[] c = new int[n]; for (int i = 0; i < n; i++) { Console.Write("a[" + i + "]="); a[i] = Convert.ToInt32(Console.ReadLine()); Console.Write("b[" + i + "]="); b[i] = Convert.ToInt32(Console.ReadLine()); c[i] = Max(a[i], b[i]); } foreach (var item in c) { Console.WriteLine(item); } } } static void Main(string[] args) { int n = Convert.ToInt32(Console.ReadLine()); Fayl q = new Fayl(); q.Cons(n); Console.ReadKey(); } 27.
internal class Attachment { public void Print(string s,string s1,string s2) { s = s.ToUpper(); s1 = s1.ToUpper(); s2 = s2.ToUpper(); if (s == s1 + s2) { Console.WriteLine(1); } else { Console.WriteLine(0); } } } static void Main(string[] args) { StreamReader read = new StreamReader("d:\\Word.txt"); string s = read.ReadLine(); string s1 = read.ReadLine(); string s2 = read.ReadLine(); Attachment a = new Attachment(); a.Print(s,s1,s2); read.Close(); Console.ReadLine(); } 28.
{ int m; int n; double[,] a; public int M { get { return m; } set { m = value; } } public int N { get { return n; } set { n = value; } } public void Create_matrix() { a = new double[m, n]; Random r = new Random(); Console.WriteLine("Matrica elementlerin kiritin': "); for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) a[i, j] = r.Next(0, 100); } public void Print_matrix() { Console.WriteLine("Matrica : "); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) Console.Write("\t" + a[i, j]); Console.WriteLine(); } } public void Min() { double min = 0, index = 0; for (int i = 0; i < m; i++) { double s = 1; for (int j = 0; j < n; j++) { s += a[i, j]; } if (i == 0) min = s; else if (s < min) { min = s; index = i; } } Console.WriteLine(index); } } static void Main(string[] args) { Minimum ob = new Minimum(); Console.Write("M = "); ob.M = Convert.ToInt32(Console.ReadLine()); Console.Write("N = "); ob.N = Convert.ToInt32(Console.ReadLine()); ob.Create_matrix(); ob.Print_matrix(); ob.Min(); Console.ReadKey(); } 29.
{ public void Print(string[] s1,string[] s2) { if (s2.Length + s1.Length > 0) { Console.WriteLine(s2.Length + 1 - s1.Length); } else { Console.WriteLine(1); } } } static void Main(string[] args) { StreamReader read = new StreamReader("d:\\Word.txt"); string s = read.ReadLine(); string[] s1 = s.Split('-'); string[] s2 = s.Split(' '); Text q = new Text(); q.Print(s1, s2); read.Close(); Console.ReadKey(); } 30.
{ public void Print(string s) { string[] s1 = s.Split(','); if (s1.Length > 0) { Console.WriteLine(s1.Length - 1); } else { Console.WriteLine(0); } } } static void Main(string[] args) { StreamReader read = new StreamReader("d:\\Word.txt"); string s = read.ReadLine(); Text q = new Text(); q.Print(s); read.Close(); Console.ReadKey(); } 31.
{ public void Print(string s) { string[] s1 = s.Split(' '); Console.WriteLine(Math.Abs(s1.Length - 1)); } } static void Main(string[] args) { StreamReader read = new StreamReader("d:\\Word.txt"); string s = read.ReadLine(); Text t = new Text(); t.Print(s); read.Close(); Console.ReadKey(); } 32.
{ public 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; } public void Print(int n) { int s = 0; for (int i = 0; i < n; i++) { int[] a = new int[n]; Console.Write("a[" + i + "]="); a[i] = int.Parse(Console.ReadLine()); if (TubSon(a[i])) { s++; } Console.WriteLine(s); } } } static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); Massiv q = new Massiv(); q.Print(n); Console.ReadKey(); } 33.
{ public void Print(string[] s,char c) { for (int i = 0; i < s.Length; i++) { if (s[i].Split(c).Length == 1) { Console.WriteLine(s[i]); } } } } static void Main(string[] args) { StreamReader read = new StreamReader("d:\\oqiw.txt"); string[] s = read.ReadLine().Split(' '); char c = char.Parse(read.ReadLine()); Text q = new Text(); q.Print(s,c); read.Close(); Console.ReadKey(); } 34.
{ int m; int n; double[,] a; public int M { get { return m; } set { m = value; } } public int N { get { return n; } set { n = value; } } public void Create_matrix() { a = new double[m, n]; Random r = new Random(); Console.WriteLine("Matrica elementlerin kiritin': "); for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) a[i, j] = r.Next(0, 100); } public void Print_matrix() { Console.WriteLine("Matrica : "); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) Console.Write("\t" + a[i, j]); Console.WriteLine(); } } public void Max() { double min = 0, index = 0; for (int i = 0; i < m; i++) { double s = 1; for (int j = 0; j < n; j++) { s *= a[i, j]; } if (i == 0) min = s; else if (s < min) { min = s; index = i; } } Console.WriteLine(index); } } static void Main(string[] args) { Matrix ob = new Matrix(); Console.Write("M = "); ob.M = Convert.ToInt32(Console.ReadLine()); Console.Write("N = "); ob.N = Convert.ToInt32(Console.ReadLine()); ob.Create_matrix(); ob.Print_matrix(); ob.Max(); Console.ReadKey(); } 35.
{ public double Sum(double a, int n, ref double s) { int i; 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; SumOff q = new SumOff(); q.Sum(a, n, ref s); Console.WriteLine(s); Console.ReadKey(); } 36.
{ public void Perfect(int a) { for (int i = a - 1; i > 0; i--) { int sum = 0, k = i; for(int j = 2; j < k; j++) { if (k % j == 0) { sum++; } } if (sum < 1) { Console.WriteLine(k); break; } } } } static void Main(string[] args) { string s = File.ReadAllText("d:\\Word.txt"); int a = Convert.ToInt32(s); Text m = new Text(); m.Perfect(a); Console.ReadLine(); } 37.
{ int m; int n; int[,] a; public int M { get { return m; } set { m = value; } } public int N { get { return n; } set { n = value; } } public void Create_matrix() { a = new int[m, n]; Random r = new Random(); Console.WriteLine("Matrica elementlerin kiritin': "); for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) a[i, j] = r.Next(0, 100); } public void Print_matrix() { Console.WriteLine("Matrica : "); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) Console.Write("\t" + a[i, j]); Console.WriteLine(); } } public void OddnumberIndex() { int numdercol = -1; for (int j = 0; j < n; j++) { bool odd = true; for (int i = 0; i < m; i++) { if (a[i, j] % 2 == 0) odd = false; } if (odd) { numdercol = j; break; } } Console.WriteLine(numdercol); } } static void Main(string[] args) { Matrix ob = new Matrix(); Console.Write("M = "); ob.M = Convert.ToInt32(Console.ReadLine()); Console.Write("N = "); ob.N = Convert.ToInt32(Console.ReadLine()); ob.Create_matrix(); ob.Print_matrix(); ob.OddnumberIndex(); Console.ReadLine(); } 38.
{ public int osiw(int[,] mat, int m, int n) { int result = -1; int[] ar = new int[m]; int san; for (int i = 0; i san = 0; for (int j = 0; j < m; j++) { ar[j] = Convert.ToInt32(mat[j, i]); } Array.Sort(ar); for (int j = 0; j < m; j++) { if (Convert.ToInt32(ar[j]) != Convert.ToInt32(mat[j, i])) { break; } else { san++; }
{ result = i; break;
} return result+1; } } static void Main(string[] args) { Console.WriteLine("Matrica olshemin kiriting:"); int m = Convert.ToInt32(Console.ReadLine()); int n = Convert.ToInt32(Console.ReadLine()); int[,] matrica = new int[m, n]; Console.WriteLine("Matrica elementlerin kiritemiz: "); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { matrica[i, j] = Convert.ToInt32(Console.ReadLine()); } } Console.WriteLine(""); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { Console.Write(matrica[i, j] + " "); } Console.WriteLine(""); } Matrix mat = new Matrix(); Console.WriteLine(mat.osiw(matrica, m, n)); Console.ReadLine(); } 39.
{ public int Count(string S) { string[] ar = S.Split(' '); int ulken=0, kish=0; for (int i = 0; i < ar.Length; i++) { for (int j = 0; j < ar[i].Length; j++) { if (ar[i][j]>='A'&&ar[i][j]<='Z') { ulken = i; i = ar.Length + 4; break; } } } for (int i = ar.Length-1; i >=0 ; i--) { for (int j = 0; j < ar[i].Length; j++) { if (ar[i][j] >= 'a' && ar[i][j] <= 'z') { kish = i; i = -1; break; } } } return kish-ulken-2; } } static void Main(string[] args) { string S = File.ReadAllText(@"C:\Users\user\Desktop\5-semestr\C# shb esap\ConsoleApplication4\4-ESAP.txt");// @"" ishine file jaylasqan orin kiritiledi. Fayl ff = new Fayl(); Console.WriteLine(ff.Count(S)); Console.ReadKey(); } 40.
{ public string jiyindi(string izbe_izlik) { string[] ar = izbe_izlik.Split(' '); int max = 0; int sum = 0; int index = 0; for (int i = 0; i < ar.Length; i++) { if (ar[i] != "") { sum = 0; for (int j = 0; j < ar[i].Length; j++) { sum += (Convert.ToInt32(ar[i][j]) - 48); } if (max < sum) { max = sum; index = i; } }
} } static void Main(string[] args) { Console.WriteLine("Izbe izlikti jazing: "); string izbeIz = Console.ReadLine(); Izbe_izlik iz = new Izbe_izlik(); Console.WriteLine(iz.jiyindi(izbeIz)); Console.ReadKey(); } 41.
{ int m; int n; double[,] a; public int M { get { return m; } set { m = value; } } public int N { get { return n; } set { n = value; } } public void Create_matrix() { a = new double[m, n]; Random r = new Random(); Console.WriteLine("Matrica elementlerin kiritin': "); for (int i = 0; i < m; i++) for (int j = 0; j < n; j++) a[i, j] = r.Next(0, 100); } public void Print_matrix() { Console.WriteLine("Matrica : "); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) Console.Write("\t" + a[i, j]); Console.WriteLine(); } } public void Zero() { int numdercol = -1; for (int j = 0; j < n; j++) { bool odd = false; for (int i = 0; i < m; i++) { if (a[i, j] == 0) odd = true; } if (odd) { numdercol = j; break; } } Console.WriteLine(numdercol); } } static void Main(string[] args) { Matrix ob = new Matrix(); Console.Write("M = "); ob.M = Convert.ToInt32(Console.ReadLine()); Console.Write("N = "); ob.N = Convert.ToInt32(Console.ReadLine()); ob.Create_matrix(); ob.Print_matrix(); ob.Zero(); Console.ReadLine(); } 42.
{ public string sortFile(string s) { string[] ar = s.Split(' '); Array.Sort(ar); s = ""; for (int i = 0; i < ar.Length; i++) { s+=ar[i]+" "; } return s; } } static void Main(string[] args) { string S = File.ReadAllText(@"C:\Users\user\Desktop\5-semestr\C# shb esap\ConsoleApplication4\4-ESAP.txt");//fileornin kiritemiz Fayl ff=new Fayl(); Console.WriteLine( ff.sortFile(S)); Console.ReadKey(); } 43.
{ public string ConvertASII(string s) { string qatar=""; for (int i = 0; i < s.Length; i++) { if (s[i]>='A'&&s[i]<='Z') { qatar+=(int)(s[i]); } else { qatar += s[i]; } } return qatar; } } static void Main(string[] args) { string S = File.ReadAllText(@"C:\Users\user\Desktop\5-semestr\C# shb esap\ConsoleApplication4\4-ESAP.txt");//fileornin kiritemiz ASII ff = new ASII(); Console.WriteLine(ff.ConvertASII(S)); Console.ReadKey(); } 44.
{ public bool isSquare(int k, ref bool t) { double x = Math.Round(Math.Sqrt(k)); t = (x * x == k); return t; } } static void Main(string[] args) { bool t = true; int k = Convert.ToInt32(Console.ReadLine()); Degree q = new Degree(); Console.WriteLine(q.isSquare(k, ref t)); Console.ReadLine(); } 45.
{ public 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()); MinimumMax q = new MinimumMax(); q.Minmax(ref x, ref y); Console.WriteLine(x); Console.WriteLine(y); Console.ReadKey(); } 46.
{ public int Count(int A, int B, int C) { int a=0, b=0; while(A>=C) { A = A - C; a++; } while (B >= C) { B = B - C; b++; } int sum=0; for (int i = 0; i < b; i++) { sum += a; } return a*b; }
static void Main(string[] args) { int A = Convert.ToInt32(Console.ReadLine()); int B = Convert.ToInt32(Console.ReadLine()); int C = Convert.ToInt32(Console.ReadLine()); TortMuyesh t = new TortMuyesh(); Console.WriteLine(t.Count(A,B,C)); Console.ReadKey(); } 47.
{ public double Cumma(int N, int K) { double S = 0; for (int i = 1 ; i <= N; i++) { S += Math.Pow(i, K); } return S; } } static void Main(string[] args) { Summa ss = new Summa(); int N = Convert.ToInt32(Console.ReadLine()); int K = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(ss.Cumma(N, K)); Console.ReadKey(); } 48. class Fayl { public string aIzlew(string S) { string[] ar = S.Split(' '); string ss = ""; for (int i = 0; i < ar.Length; i++) { for (int j = 0; j < ar[i].Length; j++) { if (ar[i][j]=='a') { ss += ar[i]+" "; break; } } }
}
static void Main(string[] args) { string S = File.ReadAllText(@"C:\Users\user\Desktop\5-semestr\C# shb esap\ConsoleApplication4\4-ESAP.txt");//fileornin kiritemiz Fayl ff = new Fayl(); Console.WriteLine(ff.aIzlew(S)); Console.ReadKey(); } Download 46.38 Kb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling