Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clc
- clear
- persons = [1 0 0 1; 0 1 1 0; 1 1 1 0; 0 0 0 1; 0 1 1 1; 1 1 0 0; 0 0 1 1; 1 0 1 1; 1 1 0 1];
- r = int16(0);
- c = int16(0);
- rowsum = int16(0);
- maxrow = int16(0);
- for r = 1 : size(persons, 1)
- for c = size(persons, 2) - 1:-1:0
- %fprintf("persons(%d,%d)\n", r, c+1)
- fprintf("c = %d -- persons(%d, %d) -- power(2, %d)\n", c, r, c+1, c)
- rowsum = rowsum + persons(r, c+1) * power(2,c);
- %fprintf("%d\n", rowsum)
- end
- %fprintf("Row Sum: %d\n", rowsum);
- %fprintf("%s\n", "Next row")
- if rowsum > maxrow
- maxrow = r;
- end
- rowsum = 0;
- end
- fprintf("Row with highest value: %d\n", maxrow)
Add Comment
Please, Sign In to add comment