Saturday 11 January 2014

Sum and average of 'n' numbers

Logic:It contains an array of elements such that,
      1.location 3000 contains no. of elements
      2.From 3000 it contains values of array elements
      3.And the location contains the sum,Average will be stored in AX


     MOV SI,3000
     MOV AX,0
     MOV CX,[SI]
repeat:   ADD SI,2
    ADD AX,[SI]
    LOOP repeat:
    ADD SI,2
    MOV [SI],AX
    MOV CX,@3000
    DIV CX
   INT 03

No comments:

Post a Comment