DEV Community

Abduvohid
Abduvohid

Posted on • Updated on

Algoritm. 1-hafta.

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


Console.WriteLine("YOSHINGIZNI KIRITING: ");
int ageInYears = int.Parse(Console.ReadLine());

int kunlar = ageInYears * 365;

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

Enter fullscreen mode Exit fullscreen mode

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;
Enter fullscreen mode Exit fullscreen mode

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

// Exercise 2 

Console.WriteLine("2 ballikdan necha marta tushirganingizni kiriting:");
int twoPoint = int.Parse(Console.ReadLine());
Console.WriteLine("3 ballikdan necha marta tushirgangizni kiriting:");
int threePoint = int.Parse(Console.ReadLine());

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

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);
Enter fullscreen mode Exit fullscreen mode

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

// Exercise 3

Console.WriteLine("Ismingizni kiriting: ");
string firstName = Console.ReadLine();
Console.WriteLine("Familiyangizni kiriting: ");
string lastName = Console.ReadLine();
bool isMale = bool.Parse(Console.ReadLine());
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}");
Enter fullscreen mode Exit fullscreen mode

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,

Top comments (0)