5-6-amaliy ish mavzu: Takrorlanuvchi operatorlar. Massivlar ustida amallar
Download 207.94 Kb.
|
Abdullayeva Sojida.5-6 amaliy ish
- Bu sahifa navigatsiya:
- 2-topshiriq
5-6-AMALIY ISH Mavzu: Takrorlanuvchi operatorlar.Massivlar ustida amallar. 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: 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); System.out.print("Massiv olchamini kiriting: "); int size = scanner.nextInt(); 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
ma'muriyatiga murojaat qiling