3. n natural soni va arifmetik progressiyaning dastlabki hadi a va ayirmasi d berilgan. Arifmetik
Download 284.9 Kb. Pdf ko'rish
|
3-variant
3-variant 3. n natural soni va arifmetik progressiyaning dastlabki hadi a va ayirmasi d berilgan. Arifmetik progressiyaning dastlabki n ta hadidan tashkil topgan massivni hosil qiling va elementlarini chiqaring. an = an-1 + d Javob: int n; double a, d; Console.Write( "a = " ); a = Convert.ToDouble(Console.ReadLine()); Console.Write( "d = " ); d = Convert.ToDouble(Console.ReadLine()); Console.Write( "n = " ); n = Convert.ToInt32(Console.ReadLine()); double [] massiv = new double [n]; for ( int i = 0; i < n; i++) { massiv[i] = Convert.ToDouble(a); a += d; } Console.WriteLine(); foreach ( double item in massiv) { Console.WriteLine(item); } 3. m va n butun musbat sonlari va m ta butun sonlar to’plmi berilgan. m x n o’lchamli matritsani shunday hosil qilingki, uning har bir ustuni kiritilgan m ta sondan iborat bo’lsin. Javob: int m = Convert.ToInt32(Console.ReadLine()); int n = Convert.ToInt32(Console.ReadLine()); double [,] ss = new double [m, n]; double s = 0; for ( int i = 0; i < m; i++) { for ( int j = 0; j < n; j++) { Console.Write( "a[" + i + "," + j + "]= " ); ss[i, j] = Convert.ToDouble(Console.ReadLine()); } Console.WriteLine(); } for ( int i = 0; i < m; i++) { for ( int j = 0; j < n; j++) { s += ss[i, j]; } } double max = ( double )s / (m * n); Console.WriteLine(max); int t = 0; for ( int i = 0; i < m; i++) { for ( int j = 0; j < n - 1; j++) { if (max > ss[i, j] && max < ss[i, j + 1]) { t = j + 1; Console.WriteLine(i + "," + j); Console.WriteLine(i + "," + t); } else if (max == ss[i, j]) { Console.WriteLine(i + "," + j); } } Console.WriteLine(); } 3. Satr berilgan. Satrdagi kichik lotin va kirill harflarining umumiy sonini aniqlovchi dastur tuzilsin Javob: string satr = (Console.ReadLine()); int n = 0; for ( int i = 0; i < satr.Length; i++) { if (satr[i] >= 1040 && satr[i] <= 1103) { n++; } } Console.WriteLine( "Kril harflari soni: " +n); int m = 0; for ( int j = 0; j < satr.Length; j++) { if (satr[j] >= 97 && satr[j] <= 122) { m++; } } Console.WriteLine( "Kichik lotin harflari soni: " +m); Download 284.9 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling