1 dan n gacha tub sonlar class Program {


Download 19.62 Kb.
Sana10.02.2023
Hajmi19.62 Kb.
#1184819
Bog'liq
Massive tayyor


1 dan n gacha tub sonlar

class Program {


static void Main(string[] args)
{int n =int.Parse(Console.ReadLine());
for (int j = 2; j <= n; j++){
int tub = 1;
for (int i = 2; i < j; i++){
if (j % i == 0) { tub = 0;
break;} }
if (tub == 1) Console.WriteLine(j);
} Console.ReadKey();}

1 dan n gacha tub sonlar va ularning soni


class Program{


static void Main(string[] args){
int n = int.Parse(Console.ReadLine());
int soni = 0; for (int j = 2; j <= n; j++)
{ int tub = 1;
for (int i = 2; i < j; i++){
if (j % i == 0) { tub = 0;
break; }} if (tub == 1) {
Console.WriteLine(j); soni++;}} Console.WriteLine(soni);
Console.ReadKey(); }

3. n-natural soni berilgan bo’lsin.Ketma – ketlikning toq elementlarini va ularning soni hisoblang.


class Program {static void Main(string[] args)


{ int n = int.Parse(Console.ReadLine());
int[] a = new int[n]; int soni = 0;
for (int i = 0; i < n; i++) {
a[i] = int.Parse(Console.ReadLine()); }
for (int i = 0; i < n; i++) {
if(a[i] % 2 == 1){
Console.WriteLine(a[i]); soni++;} }
Console.WriteLine(soni); Console.ReadKey();}
6. n-natural soni va n ta elementdan iborat ketma ketlik va k-haqiqiy soni berilgan bo’lsin.Ketma – ketlik elementlarini k soniga bo’lib
chiqing.(k!=0)
class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine());
double k = double.Parse(Console.ReadLine());
double[] a = new double[n];
for (int i = 0; i < n; i++) {
a[i] = int.Parse(Console.ReadLine()); }
for (int i = 0; i < n; i++){ a[i] = a[i] / k;
Console.WriteLine(a[i]); } Console.ReadKey(); }
18. n-natural soni berilgan bo’lsin. Bir o’lchamli sonli massivning eng katta elementini massivning birinchi elementi bilan almashtiring.

class Program {


static void Main(string[] args){
int n = int.Parse(Console.ReadLine());
int[] a = new int[n];
for (int i = 0; i < n; i++){
a[i] = int.Parse(Console.ReadLine()); }
int max = a[0];
int maxIndex = 0;
for (int i = 0; i < n; i++)
{ if (max > a[i]) { max = a[i];
maxIndex = i; }}//a0 = 1, a7 = 9
int b = a[0]; //b = a0 = 1
a[0] = a[maxIndex]; //a0 = a7 = 9
a[maxIndex] = b; //a7 = 1
for (int i = 0; i < n; i++){
Console.WriteLine(a[i]); }
Console.ReadKey() ;}
Eng kata element
class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine());
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = int.Parse(Console.ReadLine()); }
int max = a[0];
for (int i = 0; i < n; i++){
if (max > a[i]) { max = a[i]; }
} Console.WriteLine(max); Console.ReadKey();}
Eng kichik element

class Program{


static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int[] a = new int[n];
for (int i = 0; i < n; i++){
a[i] = int.Parse(Console.ReadLine()); }
int min = a[0];
for (int i = 0; i < n; i++){
if (min < a[i]) { min = a[i]; }}
Console.WriteLine(min);
Console.ReadKey(); }

17.n-natural soni berilgan bo’lsin. Bir o’lchamli sonli massivning p-elementidan , q-elementigacha bo’lgan elementlarini sonini va ularning o’rtacha qiymatini hisoblang.


class Program {


static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int p = int.Parse(Console.ReadLine());
int q = int.Parse(Console.ReadLine());
int[] a = new int[n];
for (int i = 0; i < n; i++){
a[i] = int.Parse(Console.ReadLine()); }
int s = 0;for (int i = 0; i < n; i++)
{ if (i >= p && i <= q) {
s = s + a[i]; } }
Console.WriteLine("soni " + (q - p + 1));
Console.WriteLine("yig'indisi " + s);
Console.ReadKey(); }

n-natural soni berilgan bo’lsin.Bir o’lchamli massivning o’rtacha qiymatini hisoblang.


class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine());
int[] a = new int[n];
for (int i = 0; i < n; i++){
a[i] = int.Parse(Console.ReadLine()); }int s = 0; for (int i = 0; i < n; i++) {
s = s + a[i]; }
Console.WriteLine("yig'indisi "+(double)s / n);
Console.ReadKey(); }
[a,b] intervaldagi elementlar

class Program {


static void Main(string[] args) {
int n = int.Parse(Console.ReadLine());
int a = int.Parse(Console.ReadLine());
int b = int.Parse(Console.ReadLine());
int[] massive = new int[n];
for (int i = 0; i < n; i++) {
massive[i] = int.Parse(Console.ReadLine()); } for (int i = 0; i < n; i++) {
if(massive[i] > a && massive[i] < b) {
Console.WriteLine(massive[i]); } }
Console.ReadKey(); }


Download 19.62 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling