فهرس الكتباللغة البرمجية دارت

حل السؤال

حل السؤال 24

import 'dart:io';
void main() {
  stdout.write('Enter a number (3 digits): ');
  int number = int.parse(stdin.readLineSync()!);
  if (number < 100 || number > 999) {
    print('Enter a positive integer with 3 digits.');
    return;
  }
  int onesDigit = number % 10;
  int tensDigit = (number ~/ 10) % 10;
  int hundredsDigit = number ~/ 100;
  int maxDigitPosition, big;
  if (onesDigit >= tensDigit && onesDigit >=
                                         hundredsDigit){
    maxDigitPosition = 1;
    big = onesDigit;
  } else if (tensDigit >= onesDigit && tensDigit >=
                                         hundredsDigit){
    maxDigitPosition = 2;
    big = tensDigit;
  } else {
    maxDigitPosition = 3;
    big = hundredsDigit;
  }
  print("The largest number is $big, which is the $maxDigitPosition digit from the right.");
}
العودة إلى السؤال نفسه