• Dastur kodi
  • Birlamchi ildizlar sonini topib beradi. Natija
  • soni 12ning birlamchi ildizi emas




    Download 3,64 Mb.
    bet5/5
    Sana15.02.2024
    Hajmi3,64 Mb.
    #156960
    1   2   3   4   5
    5 soni 12ning birlamchi ildizi emas ekan.


    Bu qolda ishlanishini ozgina kamchiliklari bor uni ertaga himoyaga borganda ishlab sorab ishlab qoyaman.

    Endi o‘zimga berilgan variantdagi sonni Eyler funksiyasi qiymatini tekshirish uchun dasturiy kodi tuzaman.



    Dastur kodi:
    import java.util.Scanner;
    public class CustomSquareRoot {

    public static void main(String[] args) {
    // Foydalanuvchi kiritgan sonni olish
    Scanner scanner = new Scanner(System.in);
    System.out.print("Ixtiyoriy sonni kiriting: ");
    double number = scanner.nextDouble();
    // Birlamchi ildizlari soni va ildizlarini hisoblash
    if (number >= 0) {
    int sqrtIntegerPart = (int) customSquareRoot(number); // Birlamchi ildizlari soni
    double sqrtDecimalPart = customSquareRoot(number) - sqrtIntegerPart; // Birlamchi ildizlarini hisoblash
    System.out.println("Birlamchi ildizlari soni: " + sqrtIntegerPart);
    System.out.println("Birlamchi ildizlar: " + sqrtDecimalPart);
    } else {
    System.out.println("Manfiy son uchun birlamchi ildiz mavjud emas!");
    }

    // Birlamchi ildizni hisoblash uchun funksiya
    public static double customSquareRoot(double n) {
    double approx = n / 2;
    double betterApprox;
    do {
    betterApprox = approx;
    approx = 0.5 * (approx + n / approx);
    } while (betterApprox != approx);
    return approx;
    }
    }
    Birlamchi ildizlar sonini topib beradi.
    Natija:

    Download 3,64 Mb.
    1   2   3   4   5




    Download 3,64 Mb.