我需要找到一个关于如何使用输入的数字作为迭代计数来实现循环的解决方案:
对代码进行了更改:
.data
num1: .asciiz "\nEnter the first number: "
num2: .asciiz "\nEnter the second number: "
num3: .asciiz "\nEnter the third number: "
space: .asciiz ", "
Median: .asciiz " \nThe Median is : "
.text
main:
# Print the prompt to enter the first number
li $v0,4
la $a0, num1
syscall
# Entering the first number
li $v0,5
syscall
move $t2,$v0
# Print the prompt to enter the second number
li $v0,4
la $a0, num2
syscall
# Entering the first number
li $v0,5
syscall
move $t3,$v0
#print the prompt for the third number
li $v0, 4
la $a0, num3
syscall
# Entering the third number
li $v0, 5
syscall
move $t5,$v0
# The if statement or conditional statement
bgt $t2,$t3, bigger
move $t4,$t3
bgt $t4,$t5, bigger1
move $t6,$t5
b endif
bigger:
move $t4,$t2
bigger1:
move $t6,$t4
sub $t7,$t6,$t4
syscall
endif:
li $v0, 4
la $a0, Median
syscall
li $v0,1
move $a0,$t7
syscall
#END OF PROGRAM
li $v0,10
syscall
例如,当输入40时,程序将给出1-40的所有奇数。
有人也可以告诉我如何获得中位数。中位数的输出始终为0.
由于