Calcular el promedio de x Números

Emulador Free 42

La serie termina al pulsar FIN

Pulsar R/S para seguir con otra serie


00 { 94-Byte Prgm }

01▸LBL "MEDIA"

02 CLMENU

03 CLST

04 CLRG

05 "====="

06 AVIEW

07 FIX 02

08▸LBL 01

09 XEQ 10

10 CLST

11 1

12 +

13 STO+ 00. 'Inicia el contador

14 RCL 10

15 PRX

16 STO+ 01

17 GTO 01

18▸LBL 10

19 "FIN" ' Al pulsar FIN da el resultado

20 KEY 1 XEQ 20. ' Prepara el Menu pantalla

21▸LBL 02.

22 MENU

23 "VAL?" 'Introduce los valores

24 PROMPT

25 STO 10

26 RTN

27▸LBL 20

28 CLST

29 "MEDIA="

30 RCL 01.

31 RCL 00

32 ÷ ' Cacula el promedió de los valores

33 ARCL ST X

34 AVIEW

35 STOP

36 "SUMA= "

37 ARCL 01. ' Suma de los valores introducidos

38 AVIEW

39 STOP

40 XEQ "MEDIA"

41 END




Programa promedio realizado con el emulador TI5X (TI-59)

Pulsar la tecla A para restear las memorias
Introducir cada valor pulsando la tecla B, para finalizar pulsar la tecla C para obtener el promedio.


RST           (ir a la 1ª línea del programa)

El mismo programa promedio en QBasic (QB64)


valor! = 1
total! = 0.0
count% = 0
Print "Fin=0"
ENTER:
If valor! = 0 Then
    GoTo fin
Else
    Input "Valor? ", valor!
    total! = total! + valor!
    count% = count% + 1
    GoTo ENTER
End If
fin:
count% = count% - 1
Print "Suma=", total!
Print "La media es=  "; total! / count%
End


Modificación para grabar las entradas y resultados, en el fichero "testfile.dat"
y así poderlo conservar o compartir.

Open "testfile.dat" For Output As #1
valor! = 1
total! = 0.0
count% = 0
Print "Fin=0"
ENTER:
If valor! = 0 Then
    GoTo fin
Else

    Input "Valor? ", valor!
    Select Case valor!
        Case Is > 0
            Print #1, valor!
    End Select

    total! = total! + valor!
    count% = count% + 1
    GoTo ENTER
End If
fin:
count% = count% - 1
Print "Suma=     ", total!
Print "La media es=  "; total! / count%
Print #1, "Suma= "; total!
Print #1, "Media="; total! / count%
Close #
End

Para leer cualquier nombre de archivo

Cls Input "Archivo? ", file$ dat$ = ".dat" test$ = file$ + dat$
print test$
Open test$ For Input As #1 While Not EOF(1) Line Input #1, linea$ Print línea$ Wend Close #1




Juego de los Numeros

NR? 9

MENOR

MAYOR

MAYOR

CORRECTO=7.

PUNTOS=4.

NR? 7

MAYOR

MAYOR

CORRECTO=10.

PUNTOS=3.


00 { 178-Byte Prgm }

01▸LBL "NRO→"

02 CLST

03 CLMENU

04 MENU

05 RAN

06 10

07 ×

08 1

09 +

10 IP

11 STO "CO"

12 0

13 STO "NR"

14 0

15 STO "PUN"

16▸LBL "EN"

17 FIX 00

18 INPUT "NR"

19 RCL ST X

20 RCL "CO"

21 X=Y?

22 XEQ "BIEN"

23 RCL "PUN"

24 1

25 +

26 STO "PUN"

27 RCL "CO"

28 RCL "NR"

29 X>Y?

30 GTO "ME"

31 GTO "MA"

32▸LBL "ME"

33 CLST

34 "MENOR"

35 AVIEW

36 PSE

37 GTO "EN"

38▸LBL "MA"

39 CLST

40 "MAYOR"

41 AVIEW

42 PSE

43 GTO "EN"

44▸LBL "BIEN"

45 CLST

46 "CORRECTO="

47 ARCL "NR"

48 AVIEW

49 STOP

50 "PUNTOS="

51 RCL "PUN"

52 1

53 +

54 ARCL ST X

55 AVIEW

56 STOP

57 .END.



Reescribo el mismo programa en Quick Basic (QB64)




Randomize Timer
correcto = Int(Rnd * 10) + 1
nro = 0
puntuaje = 0
Do While correcto <> nro
    Input "Ingrese Nro:? ", nro
    If nro = correcto Then
        Print "Bien"
        Print puntuaje
    Else
        puntuaje = puntuaje + 1
        If nro > correcto Then
            Print " es menor"
        Else
            Print " Es mayor"
        End If
    End If
Loop