Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Develop an LC3 assembly program that asks the user for a number, computes its fa

ID: 3729560 • Letter: D

Question

Develop an LC3 assembly program that asks the user for a number, computes its factorial and displays it back to the user. The program will have to change the user input from a string to an int, compute its factorial, then change it back to a string in order to display it back to the user. Below is a pseudocode for the main program process.
buffer = input("Enter a number: ")
number = int(buffer)
result = factorial(number)
print("The factorial of", str(number), "is", str(result))

## Comments on the code are highly appreciated.

Explanation / Answer

Please relate this to your code language. I have developed this pseudocode in C#.

static void Main(string[] args)
{
Console.WriteLine("Enter a number: ");
string number = Console.ReadLine(); // GET STRING FROM USER
int num = Convert.ToInt32(number); //CHANGED THE USER INPUT FROM A STRING TO AN INT
int result = factorial(num); //CALL FACTORIAL METHOD AND PASS VALUE GIVEN BY USER
Console.WriteLine("The factorial of" + number + " is " + result.ToString());
Console.ReadLine();
}

/// <summary>
/// THIS FUNCTION FINDS FACTORIAL OF A NUMBERS AND RETURNS THE VALUE
/// </summary>
/// <param name="number"></param>
public static int factorial(int number)
{
// INITIALIZE I AND FACT
int i, fact;
//STORE VALUE GIVEN BY USER INTO FACT
fact = number;
//NOW USING LOOP ITERATE AND GET THE VALUE
for (i = number - 1; i >= 1; i--)
{
fact = fact * i;
}
// RETURN THE FACTORIAL TO THE CALLER OF THIS METHOD
return fact;
}