## DEV Community

Abduvohid

Posted on • Updated on

# Algoritm. 1-hafta.

``````// Exercise 1
using System.ComponentModel.DataAnnotations;
using Microsoft.VisualBasic;

Console.WriteLine("YOSHINGIZNI KIRITING: ");

int kunlar = ageInYears * 365;

Console.WriteLine(\$"Yoshingizda {kunlar} kun bor.");

``````

Bu masalaning shartida yoshni kunlarga o'tkazishni so'ragan.

Yechish: Birinchi o'rinda, Yoshini so'rab olamiz, hohlasak albatta. Man so'rashni afzal ko'raman, chunki kodingiz chiroyliroq bo'ladi. Ikkinchida, ageInYears degan o'zgaruvchi yaratamiz, aytgan yoshini saqlash maqsadida. Uchinchidan, kunlar degan o'zgaruvchi yaratamiz yoshi va 365 kunni bir-biriga ko'paytirgan holda

``````int kunlar = ageInYears * 365;
``````

ko'rinishida yozamiz va oxirida kunlarni Console.Writeline komandasi orqali ekranga chiqaramiz.

``````// Exercise 2

Console.WriteLine("2 ballikdan necha marta tushirganingizni kiriting:");
Console.WriteLine("3 ballikdan necha marta tushirgangizni kiriting:");

int total = (twoPoint * 2) + (threePoint * 3);
Console.WriteLine(\$"Jami to'plagan balingiz {total}");
``````

Bu masalaning shartida basketbolda 2 ballik hamda 3 ballikdan otgan jami ballarni so'ragan.

Yechish: Bu masalani yechishda, oldin 2 ballikdan necha marta otganini hamda 3 ballikdan nechi marta otganini Console komandasi orqali soraymiz. Keyin total nomli o'zgaruvchi yaratib

``````int total = (twoPoint * 2) + (threePoint * 3);
``````

ko'rinishida yozib olamiz.
Hamda yana Console komandasi bilan ekranga chiqaramiz.

``````// Exercise 3

Console.WriteLine("Ismingizni kiriting: ");
Console.WriteLine("Familiyangizni kiriting: ");
string gender;
TextInfo TTC = new CultureInfo("en-US", false).TextInfo;
firstName = TTC.ToTitleCase(firstName);
lastName = TTC.ToTitleCase(lastName);
if (isMale == true)
{
gender = "Mr";
}else
{
gender = "Mrs";
}
Console.WriteLine(\$"{gender}. {lastName} {firstName}");
``````

Yechish: Bu masalani yechishda, birinchi userni ismini so'rab, firstName nomli o'zgaruvchida saqlaymiz. Keyin familiyasini so'rab, lastName nomli o'zgaruvchida saqlaymiz. Uchinchi, isMale nomli bool o'zgaruvchi yaratamiz,