|
Kompyuter tizimlari kafedrasi
|
bet | 127/154 | Sana | 08.01.2024 | Hajmi | 5,29 Mb. | | #131939 |
Bog'liq MajmuaMisol.3. Arifmetik amallarni hisoblaydigan dastur tuzing.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EKUB
{
class Program
{
static void Main(string[] args)
{
int a, b;
float natija;
char amal;
a = int.Parse(Console.ReadLine());
b = int.Parse(Console.ReadLine());
Console.WriteLine("Arifmetik amallar");
Console.WriteLine("+: c=a+b");
Console.WriteLine("-: c=a-b");
Console.WriteLine("*: c=a*b");
Console.WriteLine("/: c=a/b");
Console.WriteLine("Amalni tanlang (+,-,*,/):");
amal = char.Parse(Console.ReadLine());
switch (amal)
{
case '+': natija = a + b; Console.WriteLine("Natija " + natija); break;
case '-': natija = a - b; Console.WriteLine("Natija " + natija); break;
case '*': natija = a * b; Console.WriteLine("Natija " + natija); break;
case '/': natija = a / b; Console.WriteLine("Natija " + natija); break;
default: Console.WriteLine("Bunday amal yo'q"); break;
}
Console.ReadKey();
}
}
}
Misol.4. Kiritilgan oy va kunga qarab haftaning qaysi kuniga to’g’ri kelishi chiqarib berilsin.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
int kun, oy, h_kun, s = 0;
Console.WriteLine("Oyni kiriting");
oy = Int32.Parse(Console.ReadLine());
Console.WriteLine("Kunni kiriting");
kun = Int32.Parse(Console.ReadLine());
switch (oy)
{
case 1: s = kun;break;
case 2: s = 31 + kun; break;
case 3: s = 59 + kun; break;
case 4: s = 90 + kun; break;
case 5: s = 120 + kun; break;
case 7: s = 181 + kun; break;
case 6: s = 151 + kun; break;
case 8: s = 212 + kun; break;
case 9: s = 243 + kun; break;
case 10: s = 273 + kun; break;
case 11: s = 304 + kun; break;
case 12: s = 334 + kun; break;
default:Console.WriteLine("Oylar 12 ta bo'ladi");break;
}
h_kun = s % 7;
switch(h_kun)
{
case 0: Console.WriteLine("Dushanba"); break;
case 1: Console.WriteLine("Seshanba"); break;
case 2: Console.WriteLine("Chorshanba"); break;
case 3: Console.WriteLine("Payshanba"); break;
case 4: Console.WriteLine("Juma"); break;
case 5: Console.WriteLine("Shanba"); break;
case 6: Console.WriteLine("Yakshanba"); break;
}
}
}
}
enum turidan foydalanish(Oylar va haftalar misolida)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
enum Month
{
January, February, March, April, May, June,
July, August, September, October, November, December
}
enum Days
{
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
Sunday
}
static void Main(string[] args)
{
Month M;
int n_days = 0;
M = Month.November;
switch (M)
{
case Month.February:n_days = 28;break;
case Month.April:
case Month.June:
case Month.September:
case Month.November:
n_days = 30;
break;
default:
n_days = 31;
break;
}
Console.WriteLine(n_days);
}
}
}
|
| |