Mashqda yaratilgan kortejdagi elementlar yig‘indisini toping


Download 13.6 Kb.
Sana05.05.2023
Hajmi13.6 Kb.
#1431642
Bog'liq
algaritim


O`zbekiston Milliy Universiteti Jizzax filiali 'Amaliy matematika fakulteti ' 'Kampyuter ilimlari va dasturlash texnalogiyalari ‘ yo`nalshi 472_22 guruh talabasi Hasanova Sevaranig “Algaritim tillari va dasturlash texnalogiyalari “ fanidan 1-modul topshirig`i.
11-Variant
11. 9-mashqda yaratilgan kortejdagi elementlar yig‘indisini toping

using System;

public class Kortejlar
{
public static void Main(string[] args)
{
Tuple myTuple = new Tuple(1, 2, 3, 4, 5);
int sum = myTuple.Item1 + myTuple.Item2 + myTuple.Item3 + myTuple.Item4 + myTuple.Item5;
Console.WriteLine("Kortej elementlarining yig'indisi: " + sum);
}
}

11. VehicleType enum qiymatini oladigan va avtomobil turidagi g'ildiraklar sonini


qaytaradigan funksiya yarating

using System;


public class Vehicle
{
enum VehicleType { Sedan, Avtomabil, Truck};
private VehicleType Type { get; set; }
static int CountCarsOfType(VehicleType vehicleType, List vehicles)
{
int count = 0;
foreach (var vehicle in vehicles)
{
if (vehicle.Type == vehicleType)
{
count+=4;
}
}
return count;
}
public static void Main(string[] args)
{
List vehicles = new List();
vehicles.Add(new Vehicle { Type = VehicleType.Avtomabil });
vehicles.Add(new Vehicle { Type = VehicleType.Sedan });
vehicles.Add(new Vehicle { Type = VehicleType.Avtomabil });
vehicles.Add(new Vehicle { Type = VehicleType.Truck });
vehicles.Add(new Vehicle { Type = VehicleType.Avtomabil });
int avtoCount = CountCarsOfType(VehicleType.Avtomabil, vehicles);
Console.WriteLine("avtomobil turidagilari g'ildiraklar soni: " + avtoCount);
}
}

11. Soat, daqiqa va soniya int maydonlari bilan Time nomli tuzilma yarating.



using System;
public class DataTime
{
class Time
{
public int Hour { get; set; }
public int Minute { get; set; }
public int Second { get; set; }
}
public static void Main(string[] args)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("\n\tStatic va Mahaliy vaqt dasturimizga huch kelibsiz!\n");
DateTime dateTime= DateTime.Now;
Time time = new Time { Hour = 10, Minute = 30, Second = 0 };
Time time1 = new Time { Hour = dateTime.Hour, Minute = dateTime.Minute, Second = dateTime.Second };
Console.WriteLine($"\t{time.Hour:D2}:{time.Minute:D2}:{time.Second:D2}");
Console.WriteLine($"\t{time1.Hour:D2}:{time1.Minute:D2}:{time1.Second:D2}");
Console.ForegroundColor = ConsoleColor.White;
}
}

Download 13.6 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling