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
№4.Matnli faylda satr berilgen. ushbu satrning ichida bosh harflar qatnashgan so`zlar sonini aniqlovchi sinf yarating
Download 23.83 Kb.
|
algoritim
№4.Matnli faylda satr berilgen. ushbu satrning ichida bosh harflar qatnashgan so`zlar sonini aniqlovchi sinf yarating.
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(' ');int a=0; for (int i = 0; i < s.Length; i++){if ('A' <= s[i][0] && s[i][0] <= 'Z') a++; } uqish.Close(); Console.WriteLine(a); Console.ReadKey(); }}} _______________________________________________________________________________________________________________________________№5.A, B va P butun sonlari berilgen. P=A^B shartga tekshiruvchi mantiqiy turdagi PowerABP(A,B,P) metod tuzing. using System;public class Program{ static bool PowerABP(int a,int b,int p) { return p==Math.Pow(a,b); } public static void Main(){ int a=int.Parse(Console.ReadLine());int b=int.Parse(Console.ReadLine()); int p=int.Parse(Console.ReadLine()); Console.WriteLine(PowerABP(a,b,p)); }} _______________________________________________________________________________________________________________________________ №6.Matnli faylda satr berilgan. Shu satrning ichida hammasibosh harflar bilan kelgan so`zlar sonini aniqlovchi dastur tuzilsin. sozlerSaniClass myObj = new sozlerSaniClass(); string f = File.ReadAllText("C:\\Users\\USER\\Desktop\\JAZIW.txt"); myObj.EkrangaShigariw(f); class sozlerSaniClass{ public void EkrangaShigariw(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);} } _______________________________________________________________________________________________________________________________ №8.Matnli faylda N (N>1) natural sonı berilgen. Shu sonni murakkab songa tekshiruvchi sinf yarating. Agar berilgan son murakkab son bo`lsa 1, aks holda 0 sonini faylga chiqarilsin. string s = File.ReadAllText("C:\\Users\\USER\\Desktop\\JAZIW.txt"); int A = int.Parse(s); Quramalisan myObj = new Quramalisan();myObj.EkrangaShigariw(A);class Quramalisan{ public void EkrangaShigariw(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); _______________________________________________________________________________________________________________________________ №10.Matnli faylda N (N>3) butun soni berilgan. Shu sondan kichik bo`lgan eng katta tub sonni aniqlovchi dastur tuzilsin. string s = File.ReadAllText("C:\\Users\\USER\\Desktop\\JAZIW.txt"); int A = int.Parse(s); int apiwayisan=0; for(int i = 2; i < A; i++){apiwayisan=tekseriw(i);} Console.Write(apiwayisan); int tekseriw (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;}} _______________________________________________________________________________________________________________________________№12.N butun soni (N>0) berilgan. Bir siklnı foydalanib, S=1+1/2+3/4+……+(N-1)/N qatorning javobini hisoblovchi Sum(N,S) metod tuzilsin. Bu yerda S – kiruvchi/chiquvchi parametr. Console.Write("N=");int N = int.Parse(Console.ReadLine());double s = 1; void sum(int a, double b) { for (double i = 2; i <= a; i++){b += ((i-1)/i); } Console.WriteLine(b);} sum(N, s); _______________________________________________________________________________________________________________________________№13.Matnli faylda 0 va 1 raqamlari bilan kelgan probelsiz satr berilgan. Berilgan satr ikkilik sanoq sistemasi ko`rinishida. O`nlik sanoq sistemasiga o`tkazuvchi sinf yarating. string gap = File.ReadAllText("C:\\Users\\USER\\Desktop\\JAZIW.txt");aylandiriw obj=new aylandiriw(); obj.ekilik(gap);class aylandiriw{ public void ekilik(string f){ string binary = Convert.ToString(Convert.ToInt32(f, 2), 10); Console.WriteLine(binary); }} №15.K natural sonı berilgen. isSquare(K, T) funksiyası tuzilsin. Agar K parametri qandaydir bir butun sonning kvadratiga teng bo`lsa, bu funksiya TRUE qiymatini beradi, aks holda FALSE. Bu yerda T – mantiqiy turdagi kiruvchi/chiquvchi parametr. Console.Write("K="); int K = int.Parse(Console.ReadLine()); bool T = true; void isSquare(int a, bool t){ for(int i = 1; i < a; i++){if(i*i!=a){t=false;}else{t = true; break; } }Console.WriteLine(t);} isSquare(K,T); _______________________________________________________________________________________________________________________________ №16.Matnli faylda N1, N2 butun sonlari va S1, S2 satrlari berilgan. S1 satrdan birinchi N1 belgi, S2 satrning oxirgi N2 belgilaridan tuzilgan yangi S satrini hosil qiluvchi sinf yarating string gap = File.ReadAllText("C:\\Users\\USER\\Desktop\\JAZIW.txt"); sozler obj = new sozler(); obj.natiyje(gap); class sozler{ public void natiyje(string f){string[] d = f.Split("\n"); string a=d[0];int san1 = int.Parse(a[0].ToString()); int san2 = int.Parse(a[2].ToString());string b=d[1]; string c=d[2]; string juwap =b.Substring(0,san1)+c.Substring((c.Length-san2),san2);Console.WriteLine(juwap);}} _______________________________________________________________________________________________________________________________№17.A haqiqiy soni va N butun soni (N>0) berilgan. Bir sikldan foydalanib, S=1- A+A^2-A^3+…+(-1)^N*A^N ifodaning qiymatini hisoblovchi Sum(A,N,S) metod tuzilsin. Bu yerda S –kiruvchi/chiquvchi parametr. Console.Write("A="); double A=double.Parse(Console.ReadLine()); Console.Write("N="); int N=int.Parse(Console.ReadLine()); double S = 1; void Sum(double a,int n,double s){for(int i=1;i<=n;i++){ s+=Math.Pow(-1,i)*Math.Pow(a,i);}Console.WriteLine(s);}Sum(A,N,S); _______________________________________________________________________________________________________________________________ №18.Matnli faylda [0..7] raqamlari ketma-ketligi berilgan. Berilgan satr sakkizlik sanoq sistemasi ko`rinishida. Ikkilik sanoq sistemasiga o`tkazuvchi dastur tuzilsin. string gap = File.ReadAllText("C:\\Users\\USER\\Desktop\\JAZIW.txt");aylandiriw obj = new aylandiriw();obj.ekilik(gap); class aylandiriw{public void ekilik(string f){string natiyje = Convert.ToString(Convert.ToInt32(f, 8), 2); Console.WriteLine(natiyje);} } _______________________________________________________________________________________________________________________________ №19.Matnli faylda [0..F] raqamlari ketma-ketligi berilgan. Berilgen satr o`n oltilik sanoq sistemasi ko`rinishida. Ikkilik sanoq sistemasiga o`tkazuvchi dastur tuzilsin. string gap = File.ReadAllText("C:\\Users\\USER\\Desktop\\JAZIW.txt");aylandiriw obj = new aylandiriw();obj.ekilik(gap); class aylandiriw{public void ekilik(string f){string binary = Convert.ToString(Convert.ToInt32(f, 16), 2); Console.WriteLine(binary);}} _______________________________________________________________________________________________________________________________ №20.N natural sonları berilgan. Fibonachchi ketma-ketligining F(n) a`zosini hisoblovchi Fibonacci(N,A) metod tuzilsin. Bu yerda A – kiruvchi/chiquvchi parametr. Console.Write("N="); int N = int.Parse(Console.ReadLine()); int A=0; void Fibonachi( int n, int san){int a = 1;int b = 1; for(int i = 2; i < n; i++){san = a+b; a = b; b= san; }Console.WriteLine(san);}Fibonachi( N, A); _______________________________________________________________________________________________________________________________ №23.Matnli faylda S satri berilgen. S satrida ‘a’ harfi 3 marta qatnashgan so`zlarni aniqlovchi dastur tuzilsin. string gap = File.ReadAllText("C:\\Users\\USER\\Desktop\\JAZIW.txt"); string[]s= gap.Split();int sum = 0;for(int i=0;i _________________________________________________________________________________________________________________________________ №24. MxN 2 o`lchamli haqiqiy sonlar massivi berilgan. Ko`paytmasi eng kichik bo`lgan satr nomerini 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();} } } _________________________________________________________________________________________________________________________________ №25. Matnli faylda S, S1 satrlari berilgan. S satr ichida kelgan S1 satri olib tashlansin, aks holda o`zgartirilmay ekranga chiqaruvchi 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();string s1 = uqish.ReadLine(); if (s.IndexOf(s1) > 0) Console.WriteLine(s.Remove(s.IndexOf(s1), s1.Length));else Console.WriteLine(s); uqish.Close();Console.ReadKey(); } } } _________________________________________________________________________________________________________________________________ №26.N elementdan iborat A va B masssivlari berilgan. Yangi C massivni yaratuvchi dastur tuzilsin. C massivning elementlari ci=Max (ai,bi) bilan tenglashtirilsin. 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 n = int.Parse(Console.ReadLine());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] = int.Parse( Console.ReadLine());Console.Write("b[" + i + "]="); b[i] = int.Parse(Console.ReadLine()); c[i] = Max(a[i], b[i]); }foreach (var item in c){ Console.WriteLine(item); } Console.ReadKey(); } } } _________________________________________________________________________________________________________________________________ №27.Matnli faylda S, S1, va S2 satrlari berilgan. Agar S=S1+S2 bo'lsa ekranga 1 sonin, aks holda 0 sonin chiqaruvchi sinf yarating. (S=”abcDe”, S2=”ABc” S2=”DE”, S=S1+S2 o'rinli') 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();string s1 = uqish.ReadLine();string s2 = uqish.ReadLine();s=s.ToUpper();s1=s1.ToUpper();s2=s2.ToUpper();if (s == s1 + s2) Console.WriteLine(1); else Console.WriteLine(0); uqish.Close(); Console.ReadKey(); } } } №28. MxN ikkita o'lchamli haqiqiy sonlar massivi berilgan. Summasi eng kichik 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 = 0; 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(); } } } _______________________________________________________________________________________________________________________________ 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