misol Butun turdagi a massiv berilgan. Massivning elementlarining kvadratlaridan tashkil topgan massiv tuzilsin using System; using System. Linq; class Program { static void Main { int[] a = { 1, 2, 3, 4, }; var squares = a
tarix 30.03.2023 ölçüsü 138,52 Kb. #91557
4-14.
4-misol
Butun turdagi a massiv berilgan.Massivning elementlarining kvadratlaridan tashkil topgan massiv tuzilsin.
using System;
using System.Linq;
class Program {
static void Main() {
int[] a = { 1, 2, 3, 4, 5 };
var squares = a.Select(i => i * i).ToArray();
foreach (int i in squares) {
Console.WriteLine(i);
}
}
}
Javobi:
1
4
9
16
25
14-misol:
Satr turdagi massiv berilgan. Massivning elementlari va o’lchamlari aniqlansin. (Masalan: string []a={“for”, “while”, “if”, “continue”,} for 3, while 5, if 2, continue 8)
using System;
using System.Linq;
public class HelloWorld
{
public static void Main(string[] args)
{
string[] arr = { "for", "while", "if", "continue" };
string options = "";
for (int i = 0; i < arr.Length; i++)
{
options += $"{arr[i]} {arr[i].Length}";
}
string selectTag = $"{options}";
Console.WriteLine(selectTag);
}
}
Javobi: for 3 while 5 if 2 continue 8
2-usul:
using System;
using System.Linq;
class Program {
static void Main() {
string[] a = {"for", "while", "if", "continue"};
var elementCounts = a.GroupBy(i => i).ToDictionary(g => g.Key, g => g.Count());
foreach (var kvp in elementCounts) {
Console.WriteLine($"{kvp.Key}: {kvp.Value}");
}
}
}
Javobi: for: 1
while: 1
if: 1
continue: 1
Dostları ilə paylaş: