MIS EJERCICIOS V3


 

    /* Menor de tres números: Escribe un programa que solicite al usuario tres números enteros y muestre el menor de los tres. */ import 'dart:io'; main() { print(''' escribe un numero entero'''); var texto1 = stdin.readLineSync(); print('escribe otro numero entero'); var texto2 = stdin.readLineSync(); print('escribe otro numero entero'); var texto3 = stdin.readLineSync(); int? num1 = int.tryParse(texto1!); int? num2 = int.tryParse(texto2!); int? num3 = int.tryParse(texto3!); List tresNum = [num1, num2, num3]; tresNum.sort(); print('''

    Solución: ${tresNum} es el menor
    de los tres numeros que has introducido



    '''); }
  1. MENOR O MAYOR PERO DE OTRA FORMA MAS FACIL/* Menor de tres números: Escribe un programa que solicite al usuario tres números enteros y muestre el menor de los tres. */ import 'dart:io'; import 'dart:math'; main() { print(''' escribe un numero entero'''); var texto1 = stdin.readLineSync(); print('escribe otro numero entero'); var texto2 = stdin.readLineSync(); print('escribe otro numero entero'); var texto3 = stdin.readLineSync(); int? num1 = int.tryParse(texto1!); int? num2 = int.tryParse(texto2!); int? num3 = int.tryParse(texto3!); List tresNum = [num1, num2, num3]; print('''

    Solución: ${tresNum.cast<int>().reduce(max)} es el mayor
    de los tres numeros que has introducido



    '''); }
  2. Imagen
  3. /* Convenrtir una cadena de texto a un numero entero / void main() { String str = 'tonto'; int? num = int.tryParse(str); print('''La variable str es igual a '$str' si la convertimos en numero usando tryParse $num será el resultado '''); } / Al ejecutar.... La variable str es igual a 'tonto' si la convertimos en numero usando tryParse null será el resultado */ // si str fuera '56' seria 56 el resultado
  4. Imagen
  5. MENOR DE TRES NUMEROS OPTIMIZADO
  6. /* Menor de tres números: Escribe un programa que solicite al usuario tres números enteros y muestre el menor y el mayor de los tres. */ import 'dart:io'; void main() { print('Escribe tres números enteros:'); int num1 = int.parse(stdin.readLineSync()!); int num2 = int.parse(stdin.readLineSync()!); int num3 = int.parse(stdin.readLineSync()!); print( '${num1 > num2 ? (num1 > num3 ? num1 : num3) : (num2 > num3 ? num2 : num3) } es el mayor de los tres y ${num1 < num2 ? (num1 < num3 ? num1 : num3) : (num2 < num3 ? num2 : num3) } es el menor de los tres. Gracias por usar este programa.');
  7. Imagen
  8. entra en el canal: MIS EJERCICIOS

Comentarios