-Laboratoriya. While takrorlash operatori




Download 5,29 Mb.
bet131/154
Sana08.01.2024
Hajmi5,29 Mb.
#131939
1   ...   127   128   129   130   131   132   133   134   ...   154
Bog'liq
Majmua

11-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();
}
}
}

Download 5,29 Mb.
1   ...   127   128   129   130   131   132   133   134   ...   154




Download 5,29 Mb.

Bosh sahifa
Aloqalar

    Bosh sahifa



-Laboratoriya. While takrorlash operatori

Download 5,29 Mb.