5-6-amaliy ish mavzu: Takrorlanuvchi operatorlar. Massivlar ustida amallar


Download 207.94 Kb.
Sana18.06.2023
Hajmi207.94 Kb.
#1590472
Bog'liq
Abdullayeva Sojida.5-6 amaliy ish


5-6-AMALIY ISH
Mavzu: Takrorlanuvchi operatorlar.Massivlar ustida amallar.

    1. Berilgan n ta haqiqiy sonlaming eng kattasi topilsin.

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Massiv olchamini va n ni olish


System.out.print("Massiv olchamini kiriting: ");
int size = scanner.nextInt();
System.out.print("n ni kiriting: ");
int n = scanner.nextInt();

// Eng katta n ta sondan eng katta elementni aniqlash


int max = Integer.MIN_VALUE; // Eng katta elementni saqlash uchun o'zgaruvchi
for (int i = 0; i < n; i++) {
System.out.print("Butun son kiriting: ");
int x = scanner.nextInt();
if (x > max) {
max = x;
}
}

// Qolgan elementlarni o'qib tashlash


for (int i = n; i < size; i++) {
System.out.print("Butun son kiriting: ");
int x = scanner.nextInt();
if (x > max) {
max = x;
}
}

// Eng katta elementni chiqarish


System.out.println("Eng katta " + n + " ta sondan eng katta element: " + max);
}
}


2-topshiriq:

  1. Bir o`lchamli sonli massivni o`rtacha qiymatidandan kichik elеmеntlarini o`rtacha qiymati хisоblansin.

import java.util.Scanner;

public class Main {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Massiv olchamini olish


System.out.print("Massiv olchamini kiriting: ");
int size = scanner.nextInt();

// Massiv elementlarini olish


int[] arr = new int[size];
for (int i = 0; i < size; i++) {
System.out.print((i + 1) + "-elementni kiriting: ");
arr[i] = scanner.nextInt();
}

// O'rtacha qiymatni hisoblash


double sum = 0;
for (int i = 0; i < size; i++) {
sum += arr[i];
}
double average = sum / size;

// O'rtachadan kichik elementlarni hisoblash


int count = 0;
for (int i = 0; i < size; i++) {
if (arr[i] < average) {
count+=arr[i];
}
}

// Kichik elementlar sonini va o'rtacha qiymatni ekranga chiqarish


System.out.println("O'rtacha qiymat: " + average);
System.out.println("O'rtachadan kichik elementlari yig'indisi: " + count);
}
}

Download 207.94 Kb.

Do'stlaringiz bilan baham:




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