Given below is the MIPS code and output for the question. Please do rate if it helped. Thank you.
.data
prompt: .asciiz "Please
enter a positive integer: "
message: .asciiz "User input is : "
space: .asciiz "\n
"
outputeven: .asciiz "\nNumber of even
factors:"
outputodd: .asciiz "\nNumber of odd
factors:"
.text
main:
#prompt the user
li $v0, 4
la $a0, prompt
syscall
#read int input from user
li $v0, 5
syscall
move $t1,$v0 # store n in $t1
#display the user input
li $v0, 4
la $a0, message
syscall
li $v0, 1
move $a0, $t1
syscall
add $t2,$zero, 2
move $t3,$zero #counter for even factors
add $t4, $zero, 1 #counter for odd factors
loop:
#check if the current number t2 divides n
remu $t5,$t1,$t2
bne $t5,$zero,next #not divisible, goto next
#divisible, so check if $t2 is an odd factor or even
factor
#for this divide by 2 and check remainder
add $t5,$zero, 2
remu $t5,$t2,$t5
bne $t5,$zero,increment_odd
add $t3, $t3, 1 #increment even counter
j next
increment_odd:
add $t4, $t4, 1
next:
add $t2,$t2,1
ble $t2,$t1,loop
#display odd factors
li $v0,4
la $a0,outputodd
syscall
li $v0, 1
move $a0,$t4
syscall
#display the even factors
li $v0, 4
la $a0, outputeven
syscall
li $v0, 1
move $a0, $t3
syscall
#exit
li $v0,10
syscall
output
Please enter a positive integer: 20
User input is : 20
Number of odd factors:2
Number of even factors:4
-- program is finished running --
Please enter a positive integer: 27
User input is : 27
Number of odd factors:4
Number of even factors:0
-- program is finished running --
A factor of an integer N is an integer that divides N evenly. Note that 1...
In HTML write a program that calculates and displays all factors of a number with a function. A factor is any number that divides into a number evenly. For examples: Factors of 20 are 1,2,4,5,10,20 For the program: Prompt the user for a number or use an input Call a function to calculate all factors using loops and conditionals and modulus Display all factors to the page Bonus +5 If the factor is Even : Print it in Green If...
In Java* Write a program that reads an arbitrary number of 20 integers that are in the range 0 to 100 inclusive. The program will ask a user to re-enter an integer if the user inputs a number outside of that range. The inputted integers must then be stored in a single dimensional array of size 20. Please create 3 methods: 1. Write a method public static int countEven(int[] inputArray) The method counts how many even numbers are in...
2: Use mathematical induction to prove that for any odd integer n >= 1, 4 divides 3n + 1 ====== Please type / write clearly. Thank you, and I will thumbs up!
Question 4 (3 mark) : Write a Java program to ask the user to input an integer number from the keyboard. The output should indicate whether it is positive, zero, or negative, an even number or an odd number. REQUIREMENTS • Your code should ask user to input an integer number, then decide its sign and parity based on this input. • Your code should use if-else statement. Your code must work exactly as the specification and the output should...
For Python debugExercise12.py is a recursive function that accepts an integer argument, n, and prints the numbers 1 up through n. By debugging these programs, you can gain expertise in program logic in general and the Python programming language in particular. def main(): # Local variable number = 0 # Get number as input from the user. number = int(input('How many numbers to display? ')) # Display the numbers. print_num(number) # The print_num function is a a recursive function #...
Complete the Python program below that performs the following operations. First prompt the user to input two integers, n and m. If n<m, then print the odd positive integers that are less than m (in order, on a single line, separated by spaces). If man, then print the even positive integers that are less than n (in order, on a single line, separated by spaces). If neem, then print nothing. For instance, if the user enters 5 followed by 10,...
c++ please (1) Write a program that prompts the user to enter an integer value N which will rpresent the parameter to be sent to a function. Use the format below. Then write a function named CubicRoot The function will receive the parameter N and return'its cubic value. In the main program print the message: (30 Points) Enter an integer N: [. ..1 The cubic root of I.. ] is 2 update the code om part and write another function...
the user should be prompted to enter an integer and then your program will produce another integer depending on whether the input was even or odd. The following is an example of what you might see when you run the program; the input you type is shown in green (press Enter at the end of a line), and the output generated by the program is shown in black text. Enter an integer: 1234 Number is even, taking every other digit...
A perfect number is a positive integer that is equal to the sum of its (proper) positive divisors, including 1 but excluding itself. A divisor of a number is one which divides the number evenly (i.e., without a remainder). For example, consider number 6. Its divisors are 1, 2, 3, and 6. Since we do not include number itself, we only have 1, 2, and 3. Because the sum of these divisors of 6 is 6, i.e., 1 + 2...
Java programming 1. Write a program that reads an unspecified number of integers, determines how many positive and negative value have been read, and computes the total and average of the input values (not counting zeros. Your program ends with the input 0. Display the average as a floating point number Here are sample runs: (red indicates a user input) Enter an integer, the input ends if it is 0: 1 2 -1 3 0 The number of positives is...