II-BOB. MANTIQIY AMALLARNING AMALIY ASOSLARI
2.1-Mavzu: Mantiqiy amallarga oid masalalar uchun sinf va metodlar yaratish
Arifmetik amallarga oid dasturlar:
C# dasturlash tilida yig’indini ayirma kupaytma hamda bulinmani hisoblashga oid dasturini quyidagicha tuzamiz
using System;
namespace Mantiqiy_amallar{
class qushish_amali {}
class Program
{
static void Main()
{
// Ikki sonni foydalanuvchi kiritadi
Console.WriteLine("Ikkita sonni kiriting:");
Console.Write("Birinchi son: ");
int son1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Ikkinchi son: ");
int son2 = Convert.ToInt32(Console.ReadLine());
// Yig'indini hisoblash va natijani chiqarish
int yigindi = son1 + son2;
Console.WriteLine("Natija: " + yigindi);
}
}
class ayirish_amali { }
class Program
{
static void Main()
{
// Ikki sonni foydalanuvchi kiritadi
Console.WriteLine("Ikkita sonni kiriting:");
Console.Write("Birinchi son: ");
int son1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Ikkinchi son: ");
int son2 = Convert.ToInt32(Console.ReadLine());
// Yig'indini hisoblash va natijani chiqarish
int ayirma = son1 - son2;
Console.WriteLine("Natija: " + ayirma);
}
}
class kupaytma_amali { }
class Program
{
static void Main()
{
// Ikki sonni foydalanuvchi kiritadi
Console.WriteLine("Ikkita sonni kiriting:");
Console.Write("Birinchi son: ");
int son1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Ikkinchi son: ");
int son2 = Convert.ToInt32(Console.ReadLine());
// Yig'indini hisoblash va natijani chiqarish
int kupaytma = son1 * son2;
Console.WriteLine("Natija: " + kupaytma);
}
}
class bulish_amali { }
class Program
{
static void Main()
{
// Ikki sonni foydalanuvchi kiritadi
Console.WriteLine("Ikkita sonni kiriting:");
Console.Write("Birinchi son: ");
int son1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Ikkinchi son: ");
int son2 = Convert.ToInt32(Console.ReadLine());
// Yig'indini hisoblash va natijani chiqarish
int bulish = son1 / son2;
Console.WriteLine("Natija: " + bulish);
}
}
}
|