|
-Laboratoriya. While takrorlash operatori
|
bet | 131/154 | Sana | 08.01.2024 | Hajmi | 5,29 Mb. | | #131939 |
Bog'liq Majmua11-Laboratoriya. While takrorlash operatori.
Misol 6. while operatorida 10 gacha bo’lgan sonlarni chiqaring
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 i = 0; // dastlabki qiymat yuklash inisilizatsiya
while (i < 10) // shart
{
Console.WriteLine("i = {0}", i);
i++; // increment
}
Console.ReadKey();
}
}
}
Misol7. break operatoriga misol
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 i = 0;
while (true)
{
Console.WriteLine("i = {0}", i);
i++;
if (i > 10)
break;
}
Console.ReadKey();
}
}
}
Misol8. 2 ta sikl hosil qilish
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 i = 0, j = 1;
while (i < 2)
{
Console.WriteLine("i = {0}", i);
i++;
while (j < 2)
{
Console.WriteLine("j = {0}", j);
j++;
}
}
Console.ReadKey();
}
}
}
Misol9. Berilgan natural n va m uchun hisoblansin:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int n, m, i = 2, j;
float p, s=0;
n = Int32.Parse(Console.ReadLine());
m = Int32.Parse(Console.ReadLine());
while (i <= n)
{
p = 1; j = 3;
while (j <= m)
{
p *= (i * i) / j;
j += 1;
}
s += p;
i += 1;
}
Console.WriteLine(s);
Console.ReadKey();
}
}
}
Misol10. 2 ta son uchun EKUB ni hisoblang
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int n, m;
n = Int32.Parse(Console.ReadLine());
m = Int32.Parse(Console.ReadLine());
while (n != m)
{
if (n > m)
{
n = n - m;
}
else
{
m = m - n;
}
}
Console.WriteLine(n);
Console.ReadKey();
}
}
}
Boshqacha usulda
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int n, m;
n = Int32.Parse(Console.ReadLine());
m = Int32.Parse(Console.ReadLine());
while (n != 0 && m != 0)
{
if (n > m)
{
n = n % m;
}
else
{
m = m % n;
}
}
Console.WriteLine(n + m);
Console.ReadKey();
}
}
}
|
| |