#include <iostream.h>
main()
{
int a[] = {12, 5, 34, 75, 10, 25};
int n = 6;
int max, i;
for (max = i = 0; i < n; i++)
if (a[i] > max)
max = a[i];
cout << max << end1;
}
Este programa calcula el máximo de los elementos del array a, almacenádolo en la variable max.
#2: (Implementación de la condición if-then-else) Se pretende realizar un programa en lenguaje ensamblador equivalente al siguiente código en C:
#include <iostream.h>
main()
{
int a[] = {-12, 5, -34, -75, -10, 25};
int n = 6;
int max, i;
int npos, nneg;
for (i = npos = nneg = 0; i < n; i++)
if (a[i] > 0)
npos++;
else
nneg++;
cout << “+: “ << npos << “; -: “ << nneg << end1;
}
Utilice el registro BX AH para Contar los números positivos y BL para Contar los números negativos
y a continuacion vemos cuantos numeros negativos y positivos tenemos.
No hay comentarios:
Publicar un comentario